Skip to content

X-Size hardening rejected legit headers-only >2GB cache entries - #495

Merged
xroche merged 2 commits into
masterfrom
p2-xsize-headers-only
Jul 5, 2026
Merged

X-Size hardening rejected legit headers-only >2GB cache entries#495
xroche merged 2 commits into
masterfrom
p2-xsize-headers-only

Conversation

@xroche

@xroche xroche commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Follow-up to the #494 review. #493 rejects any X-Size outside [0, INT_MAX) at header parse time, but a headers-only entry (X-In-Cache: 0) can legitimately exceed INT_MAX: a >2GB non-html file is stored with its real size and the body on disk, so every update invalidated the entry and re-fetched the whole file. The negative check stays global; the INT_MAX check now fires only when the data sits in the zip (the write path asserts those fit an int), and the one remaining int-sized in-memory read rejects oversized entries on its own.

The cache-corrupt self-test adds a headers-only fixture: a forged X-Size above INT_MAX must survive a header probe with the size intact (this fails on the old engine), and an in-memory read of the same entry must still degrade to an invalid entry rather than a wraparound malloc.

xroche and others added 2 commits July 5, 2026 15:32
The guard from #493 bounds X-Size to [0, INT_MAX) before the header/data
split, but a headers-only entry (X-In-Cache: 0) legitimately exceeds
INT_MAX: every >2GB non-html file is stored that way, so updates
invalidated the entry and re-fetched the file. Keep the negative check
global, gate the INT_MAX half on data-in-cache (the write path asserts
those fit an int), and reject oversized entries at the one remaining
int-sized in-memory read.

-#test=cache-corrupt gains a headers-only fixture: a forged >INT_MAX
X-Size must survive a header probe with the size intact (fails on the
old code) while an in-memory read of the same entry still degrades.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
@xroche
xroche merged commit 20be48d into master Jul 5, 2026
15 checks passed
@xroche
xroche deleted the p2-xsize-headers-only branch July 27, 2026 18:26
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