Plugin interface functions: Bytes or Characters?

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
Dalai
Power Member
Power Member
Posts: 9961
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Plugin interface functions: Bytes or Characters?

Post by *Dalai »

Hey there,

just stumbled upon this little detail.

1. The WFX interface documentation says about FsContentGetValue:
maxlen The maximum number of bytes fitting into the FieldValue variable.
Since this function is one of those existing in a Unicode version, and other WFX functions are documented to use MaxLen characters, I'm wondering if the MaxLen parameter really means bytes instead of characters in this case (if a string type is returned in FieldValue parameter, of course). I guess you know that this is an important difference and detail.

2. The maxlen parameter for FsContentGetDefaultView is not explained though it's listed in the declaration. Wondering again: bytes or characters?

I'm not sure if other plugin types are affected by this, too.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
User avatar
Dalai
Power Member
Power Member
Posts: 9961
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

Thanks! :)

So the short answer is: it's bytes in FsContentGetValue, and the documentation is correct. And it looks like characters in FsContentGetDefaultView, but the documentation is incomplete.

Is there an official statement from Ghisler about this detail? I didn't find any, hence this thread.

Criticism to Ghisler:
I don't think that a developer is supposed to search the forums to find an answer to such important facts. It's supposed to be part of the plugin interface documentation. So, I guess it's time for an overhaul of the plugin interface documentation, correcting as many errors, omissions and ambiguities as possible. Over the years, there have been a lot of them.

While at it, it would be nice to convert the interface documentation to CHM to take advantage of newer features (searchable single pages, highlighting search terms with IE8+ and so on).

Conclusion: I've returned a wrong number of bytes in the FsContentGetValue functions of my plugins, potentially leading to a buffer overflow. OK, it's (partly) my own fault since I didn't follow the documentation to the letter... BTW, the WDX documentation mentions this little detail:
maxlen The maximum number of bytes fitting into the FieldValue variable. Note: When using Unicode strings, you need to divide this value by 2 to get the maximum number of characters!
Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

I recommend to use MVV's adapted plugin interface as I already do for my plugins.
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50421
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Yes, it's bytes in FsContentGetValue, that's why it is documented. Why? It accepts a wide range of data, like ANSI, Unicode names, and even a block of data for ft_fulltext search.

In FsContentGetDefaultView, it depends on whether you implement the ANSI or Unicode version - all parameters are 0-terminated strings, so the length is characters.
Author of Total Commander
https://www.ghisler.com
Post Reply