Skip to content

Validate Parquet page size before allocation - #10821

Closed
Bardakor wants to merge 1 commit into
apache:mainfrom
Bardakor:fix/parquet-page-size-validation
Closed

Bardakor wants to merge 1 commit into
apache:mainfrom
Bardakor:fix/parquet-page-size-validation

Conversation

@Bardakor

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

SerializedPageReader validates a page's compressed size against the bytes remaining in its column chunk, but previously only checked that uncompressed_page_size was non-negative. decode_page then used that untrusted value as a Vec capacity before decompression could detect a mismatch.

Parquet's column metadata already supplies a structural bound: one page's uncompressed payload cannot exceed the column chunk's total uncompressed size, which includes every page and its header. Checking that invariant before decode rejects an inconsistent file without introducing a configurable limit for valid large pages.

What changes are included in this PR?

  • Retain the column chunk's declared uncompressed size in SerializedPageReader.
  • Validate each page's uncompressed size before decode in both the sequential and offset-index paths.
  • Populate required total-uncompressed-size metadata in two page-writer test fixtures that construct column metadata directly.

Are these changes tested?

Yes. The regression constructs a tiny invalid Snappy page and verifies that both reader paths return Invalid page header before decompression. The compressed payload is intentionally invalid, so reaching the codec would produce a different error.

Commands run:

  • cargo test -p parquet
  • cargo clippy -p parquet --all-targets --all-features -- -D warnings
  • cargo +stable fmt --all -- --check
  • git diff --check

Are there any user-facing changes?

Malformed Parquet files whose page uncompressed size exceeds their column chunk total now return an error before allocating a decompression buffer. There is no public API change.

AI usage

Codex assisted with tracing the reader paths, constructing the regression test, and drafting the change. I reviewed the Parquet metadata invariant, inspected every changed line, ran the checks above, and can debug and own the final patch.

decompressor,
state,
physical_type: meta.column_type(),
column_uncompressed_size: meta.uncompressed_size(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this a value (potentially untrusted) that comes from the same file?

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.

having a stricter check here per this PR can have some value, but yes it does still leave a potential loophole via the uncompressed size field if we're aiming to fully close the loophole 🤔

@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.

@github-actions github-actions Bot added the Stale Used by workflow to mark PRs that will be auto-closed label Oct 30, 2026
@alamb

alamb commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

The PR appears abandoned -- please respond to feedback and reopen if you want to proceed

@alamb alamb closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet parquet crate Stale Used by workflow to mark PRs that will be auto-closed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SerializedPageReader allocates uncompressed_page_size bytes before validating it against the column chunk

4 participants