Skip to content

An .ndx entry's two URL halves overflow the buffer they share - #744

Merged
xroche merged 2 commits into
masterfrom
fix/binput-room
Jul 26, 2026
Merged

An .ndx entry's two URL halves overflow the buffer they share#744
xroche merged 2 commits into
masterfrom
fix/binput-room

Conversation

@xroche

@xroche xroche commented Jul 26, 2026

Copy link
Copy Markdown
Owner

PT_LoadCache__Old reads an entry's URL in two halves into one line[HTS_URLMAXSIZE * 2], and passes HTS_URLMAXSIZE as the bound for both. binput writes its NUL at s[max], so a first field that fills its whole bound leaves the second one writing line[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 .ndx reader 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 the strcpy calls 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-corrupt already makes.

Separately, and not fixed here: binput returns count + 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.

xroche and others added 2 commits July 26, 2026 22:36
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>
@xroche
xroche merged commit 9484b32 into master Jul 26, 2026
22 checks passed
@xroche
xroche deleted the fix/binput-room branch July 26, 2026 21: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