Skip to content

fix: Nested collections multiply the 512MB allocation budget arbitrarily - #639

Merged
martin-g merged 5 commits into
mainfrom
track-allocated-bytes-during-decoding
Aug 26, 2026
Merged

martin-g merged 5 commits into
mainfrom
track-allocated-bytes-during-decoding

Conversation

@martin-g

Copy link
Copy Markdown
Member

decode.rs::decode_internal (for Schema::Array & Map): safe_collection_len bounds each individual Vec/HashMap against max_allocation_bytes, but no state tracks the running total across the decoded value tree. Elements that cost zero wire bytes (null, empty records, zero-size fixed) let each ~7-byte inner array block materialize ~512MB of live Value slots, so array<array> from an attacker OCF header holds K x 512MB simultaneously from ~130 datum bytes.

Reported-by: Security scans

@Kriskras99 Kriskras99 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes are needed, but good overall

Comment thread avro/src/decode.rs Outdated

/// Debit `bytes` from the per-datum allocation budget, erroring when the
/// cumulative allocations for this datum would exceed it.
fn debit(&mut self, bytes: usize) -> AvroResult<()> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think renaming this to debit_bytes would make it a lot clearer to future readers of the code

Comment thread avro/src/decode.rs Resolved
Comment thread avro/src/decode.rs Resolved
Comment thread avro/src/decode.rs Resolved
Comment thread avro/src/decode.rs Resolved
Comment thread avro/src/decode.rs Resolved
Comment thread avro/src/decode.rs Resolved
Comment thread avro/src/reader/datum.rs Resolved
Comment thread avro/src/reader/block.rs Resolved
Comment thread avro/src/decode.rs
Comment on lines +582 to +585
assert!(
result.is_err(),
"nested collections must share one allocation budget, got {result:?}"
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the error is actually Details::MemoryAllocation

Comment thread avro/src/reader/single_object.rs Resolved
martin-g and others added 5 commits August 26, 2026 12:50
decode.rs::decode_internal (for Schema::Array & Map): safe_collection_len bounds each individual Vec/HashMap against max_allocation_bytes, but no state tracks the running total across the decoded value tree. Elements that cost zero wire bytes (null, empty records, zero-size fixed) let each ~7-byte inner array<null> block materialize ~512MB of live Value slots, so array<array<null>> from an attacker OCF header holds K x 512MB simultaneously from ~130 datum bytes.

Reported-by: Security scans
Co-authored-by: Kriskras99 <[email protected]>
Co-authored-by: Martin Grigorov <[email protected]>
Co-authored-by: Kriskras99 <[email protected]>
@martin-g
martin-g force-pushed the track-allocated-bytes-during-decoding branch from 08f2d01 to 5a7bb4a Compare August 26, 2026 09:55
@martin-g
martin-g disabled stacked auto-merge August 26, 2026 11:10
@martin-g
martin-g merged commit 496a85d into main Aug 26, 2026
16 checks passed
@martin-g
martin-g deleted the track-allocated-bytes-during-decoding branch August 26, 2026 15:40
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.

2 participants