An .ndx entry's two URL halves overflow the buffer they share - #744
Merged
Conversation
Both binput calls pass HTS_URLMAXSIZE, but they write into one line[HTS_URLMAXSIZE * 2] and binput puts its NUL at s[max]. A first field that fills its whole bound leaves the second writing line[2048], one past the array. ASan reports a stack-buffer-overflow on a crafted .ndx. Bound the second by what the first left. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
# Conflicts: # tests/Makefile.am
This was referenced Jul 27, 2026
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.
PT_LoadCache__Oldreads an entry's URL in two halves into oneline[HTS_URLMAXSIZE * 2], and passesHTS_URLMAXSIZEas the bound for both.binputwrites its NUL ats[max], so a first field that fills its whole bound leaves the second one writingline[2048], one byte past the array. ASan reports a stack-buffer-overflow on a crafted.ndx; the fix bounds the second call by what the first left.Only the legacy
.ndxreader is affected, and only a hand-made or corrupt index gets a 1024-character first field, since anything HTTrack wrote is shorter. Found while reviewing #743, which was looking at thestrcpycalls in the same function.Test 92 crafts that index and converts it. Note where its teeth are: a one-byte stack write does not reliably fault, so on an ordinary build the test mostly proves the parse still works. The sanitizer leg is what turns a regression into a hard failure, the same bargain
01_zlib-cache-corruptalready makes.Separately, and not fixed here:
binputreturnscount + 1, which over-advances when a field ends at the buffer's final NUL rather than a newline, so the next call reads one past the heap allocation. My first version of test 91 tripped it; the committed one appends a trailing entry so it exercises the field bound alone. That read overflow deserves its own change.