Harden the zip cache read path against a corrupt X-Size - #493
Merged
Conversation
A tampered X-Size in a zip cache entry wrapped into an oversized malloc (an allocation-size-too-big abort under ASan). The alloc casts to int (malloct((int) r.size + 1)), so besides a negative size, any positive value at or above INT_MAX truncates negative and wraps too; reject the whole out-of-range span before the load. -#test=cache-corrupt byte-injects a real two-entry zip (bad/oversized/ negative X-Size, blanked X-In-Cache, smashed local header, garbled deflate) and checks each entry degrades to STATUSCODE_INVALID in the same read session as its intact sibling, so one corrupt entry never taints the cache. Only the live zip format is covered; the legacy .dat reader is dead and slated for removal. Re-lands the change orphaned when it was merged into its stacked base branch instead of master. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
xroche
added a commit
that referenced
this pull request
Jul 5, 2026
* X-Size hardening rejected legit headers-only >2GB cache entries 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> * review: pin the INT_MAX boundary and the headers-only negative X-Size Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com> --------- Signed-off-by: Xavier Roche <roche@httrack.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.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 tampered X-Size in a zip cache entry wrapped into an oversized malloc (an allocation-size-too-big abort under ASan). The alloc casts to int, so besides a negative size, any positive value at or above INT_MAX truncates negative and wraps too; reject the whole out-of-range span before the load.
-#test=cache-corruptbyte-injects a real cache (bad/oversized/negative X-Size, blanked X-In-Cache, smashed header, garbled deflate) and checks each entry is rejected in-session without tainting its sibling.Only the live zip cache format is covered; the legacy .dat format is dead and slated for removal. This re-lands the change that was orphaned when #492 merged into its stacked base branch instead of master.