X-Size hardening rejected legit headers-only >2GB cache entries - #495
Merged
Conversation
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>
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.
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.