rust: reject oversized chunk compression strings before allocating - #1823
Merged
clalancette merged 1 commit intoAug 25, 2026
Merged
Conversation
official-burak
requested review from
bennetthardwick,
gasmith and
james-rms
as code owners
August 25, 2026 12:31
clalancette
approved these changes
Aug 25, 2026
clalancette
left a comment
Contributor
There was a problem hiding this comment.
Thanks, this is a nice improvement. I've found similar problems in most of the rest of the languages, which I'll fix in a follow-up PR.
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.
Changelog
ReadRequestsizes to the remaining file length when the file size is knownDocs
None.
Description
LinearReaderloads a chunk header in two steps: first the fixed prefix, thenMIN_CHUNK_HEADER_SIZE + compression_lenbytes.compression_lenis taken from the file and was passed toconsume!/insert()with no check against the chunk record length orrecord_length_limit.insert(n)resizes the buffer before any bytes are read, so a 191 KiB file that declared a ~1.69 GiB compression string drove peak RSS to about 1.69 GiB and then returnedUnexpectedEof.record_length_limitdid not prevent this. The limit is applied to parsed record bodies, and the chunk path skipped that check until after the header (including the compression string) had been requested.This PR:
BadChunkLength).record_length_limitto that header length (ChunkTooLarge).SummaryReaderread requests to the remaining file bytes whenfile_sizeis known, so the documented sans-io loop cannot allocate more than the file can contain.next_read_size()bycompressed_remaining.Well-formed files are unchanged. Regression tests cover the 1.69 GiB compression-string case both with a mismatched record length and with a matching length plus a 64x file-size record limit.
Fixes #1813