Skip to content

fix(parquet): prevent byte stream split decoder panic - #11136

Open
jaideeppyne wants to merge 8 commits into
apache:mainfrom
jaideeppyne:fix-byte-stream-split-value-count
Open

jaideeppyne wants to merge 8 commits into
apache:mainfrom
jaideeppyne:fix-byte-stream-split-value-count

Conversation

@jaideeppyne

@jaideeppyne jaideeppyne commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #11121.

BYTE_STREAM_SPLIT must bound decoding by the complete values present in its byte streams. A page count can include nulls or be corrupt; trusting it as the buffer bound lets join_streams_const index past the encoded data.

Both fixed- and variable-width decoders now derive their value count from the encoded byte length, while retaining partial-value validation. Higher-level readers report insufficient values for a truncated required page. Valid nullable pages need no column-reader special case.

The regression writes a real Parquet file, verifies its eight original values, and changes one page-header byte to declare 63 values. On unchanged upstream this panics; with this fix it returns an ordinary error.

Reproducer: malformed file, 487 bytes, valid control, standalone public-API program.

Focused verification: the baseline panic and fixed error were observed with byte-identical fixtures; 1,505 Parquet unit tests and 147 Arrow-reader tests passed (one existing ignored test in each suite), along with all-target/all-feature Parquet Clippy and formatting. Decoder tests cover oversized count estimates, partial reads, skipping, and both variable-width join paths.

Full fork CI for the published head passed, including the Arrow workspace and Parquet tests, Clippy, MSRV, wasm builds, and cross-language Archery/PyArrow/PySpark checks. The workflow skipped macOS, Windows, and documentation deployment on this run.

AI disclosure: OpenAI Codex assisted with the implementation, regression tests, standalone reproducer, and verification analysis.

@github-actions github-actions Bot added the parquet parquet crate label Sep 19, 2026
Comment thread parquet/src/encodings/decoding.rs Resolved
…_values

Reject BYTE_STREAM_SPLIT buffers shorter than num_values * type size
instead of decoding the encoded count. Exact-size input still decodes,
and oversized buffers keep the existing error. V1 pages have no non-null
count, so the column reader passes the number of complete values in the
buffer and leaves nulls to definition levels.
@Rich-T-kid

Copy link
Copy Markdown
Contributor

@jaideeppyne could you enable the CI on your fork

@jaideeppyne

jaideeppyne commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Fork Actions are enabled, and the PR branch includes current main (70d8190) so it has the current fork CI workflow. The change remains scoped to the same three Parquet files.

Fork verification: full CI run for head 0393d7a passed, including Parquet tests and Clippy, MSRV, Windows, macOS, and cross-language Archery integration. The final Required Checks job passed; documentation deployment was skipped on the fork as expected.

@alamb alamb 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.

Where was the panic that was removed?

How would someone reach this for real?

@etseidl

etseidl commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Going to mark this draft as it's waiting on submitter input

@etseidl
etseidl marked this pull request as draft November 4, 2026 23:08
@jaideeppyne

jaideeppyne commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

@alamb, the panic is at sub_src[i + j * stride] in join_streams_const, reached through the public ParquetRecordBatchReaderBuilder when a page's value count exceeds its encoded payload.

Here are actual files and a runnable public-API program:

The writer creates eight doubles and the control reads all eight back. Only zero-based byte 14 changes, from 16 to 126, declaring 63 values while the payload and footer stay in place. Verification observed index out of bounds: the len is 56 but the index is 56 on unchanged upstream. With b280e76, the identical file returns an insufficient-values error.

The update also follows @jhorstmann's suggestion: both decoder variants use the encoded count, and the column-reader workaround is removed. The new integration test exercises this file-construction path directly. Focused tests, Clippy, and formatting passed; full fork CI for the published head also passed, including the workspace and cross-language integration tests. macOS, Windows, and documentation deployment were skipped by that workflow. This follow-up and its reproducer were prepared with OpenAI Codex assistance.

@alamb alamb 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.

Thanks @jaideeppyne

Comment thread parquet/tests/arrow_reader/bad_data.rs Resolved
Comment thread parquet/src/column/reader/decoder.rs Resolved
…alues

Read the 487 byte reproducer from a checked-in fixture instead of
rewriting a page header in the test.

Both BYTE_STREAM_SPLIT decoders now error when the page holds more
encoded values than the page's value count allows. That count is an
upper bound (it includes nulls for V1 pages), so fewer encoded values
remain valid and the stride is still derived from the encoded length.

Drop the column reader unit test: nullable V1 pages are already covered
end to end by existing reader and writer tests.
@jaideeppyne

Copy link
Copy Markdown
Contributor Author

@alamb thanks for the review. 0e75fbd addresses all four comments, with replies inline:

  • The malformed 487 byte file is checked in and read directly.
  • The column reader unit test is removed; existing end to end tests already cover nullable V1 pages.
  • Both BYTE_STREAM_SPLIT decoders treat the page value count as an upper bound and reject a page with more encoded values than declared. Strict equality would break nullable V1 pages, where the count includes nulls.

The branch also merges current main (30c5c32), so CI runs the current workflow. Locally cargo test -p parquet --lib (1511 passed), cargo test -p parquet --test arrow_reader (147 passed), cargo clippy -p parquet --all-targets --all-features -- -D warnings and cargo fmt are clean. Prepared with AI assistance. Ready for another look.

@alamb alamb 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.

looks good @jaideeppyne -- I have a few more questions but this is looking very close

Comment thread parquet/src/encodings/decoding.rs Resolved
Comment thread parquet/src/encodings/decoding.rs Resolved
Comment thread parquet/tests/arrow_reader/bad_data.rs Resolved
@Rich-T-kid Rich-T-kid added the bug Squash those bugs label Nov 16, 2026

This branch has not been deployed

No deployments
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.

Out-of-bounds index in the BYTE_STREAM_SPLIT decoder on a malformed page header

5 participants