Skip to content

[59_maintenance] fix(parquet): reject Thrift list sizes larger than remaining input - #11353

Merged
alamb merged 3 commits into
apache:59_maintenancefrom
Jefffrey:backport_10979
Oct 5, 2026
Merged

alamb merged 3 commits into
apache:59_maintenancefrom
Jefffrey:backport_10979

Conversation

@Jefffrey

@Jefffrey Jefffrey commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

…pache#10979)

# Which issue does this PR close?

- Closes apache#10920.

# Rationale for this change

`read_thrift_vec` reserved `Vec` capacity from the compact list header's
declared element count before reading any element. A 23-byte footer
whose `schema` list claimed ~109 million `SchemaElement`s asked for ~10
GB. Allocation failure aborts the process; `ParquetMetaDataReader` never
returns an error.

Each list element occupies at least one byte on the wire, so the
declared size can be bounded by the bytes remaining in the metadata
slice. That slice is already length-limited by the footer; this check is
the level below.

# What changes are included in this PR?

- `ThriftCompactInputProtocol::remaining_bytes` reports unread length
for slice-backed input (`ThriftSliceInputProtocol`). Stream-backed input
(`ThriftReadInputProtocol`) leaves it unset.
- `read_thrift_vec` returns `ParquetError::General` when the declared
size exceeds remaining input, and only then calls `Vec::with_capacity`.

No public API change.

# Are these changes tested?

Unit tests in `parquet_thrift`:
- well-formed 2-element `i32` list still decodes
- 14-element header with no payload returns an error
- declared size 109_002_364 with two leftover bytes returns an error
(the schema-list case from the issue)

`cargo test -p parquet --lib parquet_thrift` and `cargo clippy -p
parquet --lib --tests --all-features -- -D warnings`.

# Are there any user-facing changes?

Malformed footers that previously aborted now return `ParquetError`.
Valid files are unchanged.

# AI Disclosure

Assisted draft of the remaining-bytes check and regression tests.
Reviewed against the compact protocol list encoding and verified with
the tests above.

Co-authored-by: Marcelo Tesla <[email protected]>
@Jefffrey

Jefffrey commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

looks like ill need to modify the let chain since that was stabilized in 1.88, but branch 59 has msrv of 1.85

@alamb

alamb commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Updating to get clean CI run

@alamb
alamb merged commit cd7a8d2 into apache:59_maintenance Oct 5, 2026
19 of 21 checks passed
@alamb

alamb commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Squash those bugs parquet parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants