Skip to content

Fix cbDest argument of StringCbPrintfW#203

Open
topolarity wants to merge 1 commit intosciapp:developfrom
topolarity:ct/fix-path-append
Open

Fix cbDest argument of StringCbPrintfW#203
topolarity wants to merge 1 commit intosciapp:developfrom
topolarity:ct/fix-path-append

Conversation

@topolarity
Copy link
Contributor

Microsoft has documented that this is the size of the destination buffer in bytes, not characters:

The size of the destination buffer, in bytes. This value must be sufficiently large to accommodate the final formatted string plus the terminating null character. The maximum number of bytes allowed is STRSAFE_MAX_CCH * sizeof(TCHAR).

PATH_MAX is already limited to 260 on Windows, so this mistake means that paths longer than ~130 characters are truncated.

They are searched in that order.
Use AddDllDirectory to add additional user directories to the search.
*/
handle = LoadLibraryExW(w_pathname, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
Copy link
Contributor Author

@topolarity topolarity Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unusual to call LoadLibraryExW with an absolute path and the LOAD_LIBRARY_SEARCH_DEFAULT_DIRS flag, since no searching is done for an absolute path (regardless of flags).

Should this be:

Suggested change
handle = LoadLibraryExA(pathname, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);

?

Microsoft has documented that this is the size of the destination buffer
in bytes, not characters.

PATH_MAX is already limited to 260 on Windows, so this mistake means
that paths longer than ~130 characters are truncated.
@IngoMeyer441 IngoMeyer441 changed the base branch from master to develop March 2, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant