Repository navigation
A size read from a file or a stream no longer decides an allocation - #196
Merged
Merged
Conversation
A chunk's stored and uncompressed lengths came from the index and sized a buffer before anything checked them, and zstd's decode_all had no output limit: one corrupt record, or one hostile frame, was a multi-gigabyte allocation and an abort. A records stream's entry len sized its payload the same way, and a header with no terminating NUL was read without limit. format::read_frame refuses a frame that would run past the end of the trunk, or that no chunk could be (over 4 GiB), before allocating it. format::decode_frame refuses output beyond the uncompressed length the index records. read_chunk_raw keeps its shape: the read still happens before the seqlock race check, so a read that fails mid-collapse stays retryable. records::read_payload takes a payload as it arrives instead of reserving the claim, so a stream that claims more than it delivers fails short. records::read_header stops at 1 MiB, far past any metadata record. Used by the query, store, grain and import reads, the records reader, the timber-filter reader and the consumer protocol. Co-Authored-By: Claude Sonnet 5.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.
From the full-read sweep: places where a length taken from a file or a stream sized a buffer before anything checked it.
Problem
.ringsrecord and sized a buffer;zstd::stream::decode_allhad no output limit. One corrupt record, or one hostile frame (a megabyte of zeros is a few dozen bytes), was a multi-gigabyte allocation and an abort.len=sized the entry payload the same way, and a header with no terminating NUL was read without limit (read_until(0)).Change
Chunk reads (query, store, grain build and extend, import):
format::read_framerefuses a frame that would run past the end of the trunk, or that no chunk could be (over 4 GiB), before it allocates;format::decode_framerefuses output beyond the uncompressed length the index records.read_chunk_rawkeeps its shape: the read still happens before the seqlock race check, so a read that fails mid-collapse stays retryable rather than becoming an error.Record streams (records reader,
timber-filter, the consumer protocol):records::read_payloadtakes a payload as it arrives instead of reserving the claim, so a stream that claims more than it delivers fails short;records::read_headerstops at 1 MiB, far past any metadata record.Behaviour changes
decode_alldid; my first draft refused it and a test caught that.Checked with the CLI
With one chunk's index record patched:
Both exit 1 instead of attempting the allocation.
Tests
read_frame: a frame where the index says, past the end, a start beyond the file, a length no chunk has, an overflowing range, just over the bound.decode_frame: exact, a megabyte-of-zeros bomb refused when the index says less, a claim no chunk has, garbage, empty.read_payloadandread_header: a claim far larger than the stream, exact and short, an endless header; an entry claiming 9 TB through the realReaderis a truncated stream.Not here
The newline-free input caps, the intake tick and the
importverify/overlap bounds are separate changes.🤖 Generated with Claude Code