Windows builds alias snprintf to _snprintf, which leaves a truncated string unterminated - #1752
Merged
Merged
Conversation
htslib.h defined snprintf as _snprintf under _WIN32. Microsoft documents _snprintf as writing no terminating NUL when it truncates, so every raw snprintf in the engine produced an unterminated string on Windows, and only there. A user hit it through htsblk.msg[80]: the crawler aborted in htsparse.c reading a failure message that had filled the field. Drop the alias, route the writers of r.msg through htsblk_failf(), and add a test that fails on any macro renaming a C99 printf call, since a Linux build cannot see one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
Review findings on this branch. Test 490 collided with the number PR #1743 claims, so the file moves to 491. Its scan reported a clean tree whatever the file list held, so it now floors the count. It also missed the alias handed to the compiler rather than written in a header, which is how a Visual Studio build would carry one, so it reads the project files too. The no-argument message in htsback.c goes back to snprintf: its text is 65 bytes, so it cannot fill the field and the conversion bought nothing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A user reported WinHTTrack 3.50-2 aborting with
size < sizeof_sourceathtsparse.c:4976. That line copiesback[b].r.msg, and the abort says those 80 bytes held no terminating NUL.htslib.haliasedsnprintfto_snprintfunder_WIN32. Microsoft documents_snprintfas writing no terminator when it truncates, while the UCRTsnprintfthe alias hid is C99-conformant. So the engine's 89 rawsnprintfcalls left their destination unterminated on Windows and nowhere else. Dropping the alias is the fix.The six failure messages that land in
r.msgnow go throughhtsblk_failf(), which clips. Three carry text the crawl does not control, and do overflow 80 bytes: a link's port, a server'sContent-Encoding, and the resolver's message.Test 491 fails on any macro renaming a C99 printf call, and on the same alias handed to the compiler as a define. A Linux build sees neither.
Closes #1753