Repository navigation
fix(parquet): return error instead of panic on corrupt PLAIN BYTE_ARRAY pages - #12179
Merged
Merged
Conversation
…AY pages ByteArrayDecoderPlain::skip did not check value lengths against the page, so a corrupt length moved the offset past the end of the buffer and the next read underflowed `buf.len() - offset`. read also divided by max_remaining_values, which is 0 on a v2 page whose header claims every value is null. skip now returns the same EOF error as read, and read returns Ok(0) when there is nothing to read. ByteViewArrayDecoderPlain::skip had the same unchecked loop and gets the same check. Co-authored-by: Isaac <[email protected]>
Jefffrey
approved these changes
Nov 12, 2026
Member
Author
|
Thanks @Jefffrey ! |
dragonknightk
pushed a commit
to dragonknightk/arrow-rs
that referenced
this pull request
Nov 13, 2026
…apache#12215) # Which issue does this PR close? - Closes apache#12200 # Rationale for this change `ByteViewArrayDecoderPlain::read_impl` adds the page's `u32` length prefix to `start_offset` without an overflow check. On a 32-bit target (`wasm32`, `i686`) a corrupt length such as `0xFFFF_FFFC` wraps `end_offset` to a value below `start_offset`, the `end_offset > buf_len` check passes, and `buf.get_unchecked(start_offset..end_offset)` is called with an inverted range. apache#12179 fixed the same pattern in `skip`; `read` was left out. `ByteArrayDecoderPlain::read` has the same unchecked addition. It uses a checked slice, so there it is a panic rather than UB, but it is the same bug on the same input, so I fixed both. # What changes are included in this PR? Both `read` paths compute the end offset with `checked_add(..).filter(|&end| end <= buf.len())` and return the existing `EOF` error, the same form apache#12179 used for `skip`. # Are these changes tested? Yes, one unit test per decoder reads a page whose first length is `0xFFFF_FFFC` and expects an `EOF` error. On 64-bit the addition cannot wrap, so the tests pass there with and without the fix. I ran them on `i686-unknown-linux-gnu` (`cargo test -p parquet --lib --no-default-features --features arrow --target i686-unknown-linux-gnu`): - without the fix, debug: both tests panic with an add overflow at the changed lines; - without the fix, release: the offset decoder panics on the slice, and the view decoder returns `Ok` from the inverted range instead of an error; - with the fix: both pass. I did not run Miri (not available in my toolchain); CI runs it. # Are there any significant user-facing changes? No. A corrupt page that could panic or hit undefined behaviour on 32-bit targets now returns an error. --- AI disclosure: the patch and tests were drafted with AI assistance (Claude); I reviewed every line and ran fmt, clippy and the parquet array reader tests, plus the i686 runs above.
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.
Which issue does this PR close?
Rationale for this change
ByteArrayDecoderPlaincan panic on corrupt PLAINBYTE_ARRAYpages, and both panics can be reached fromParquetRecordBatchReader.skipmoves past the end of the page without an error. The nextreadon that page then underflowsbuf.len() - offset.readdivides bymax_remaining_values, which is 0 on a v2 page whose header claims every value is null.The issue has repro steps.
What changes are included in this PR?
ByteArrayDecoderPlain::skipchecks each value's end offset against the page, usingchecked_add, and returns the sameParquetError::EOF("eof decoding byte array")thatreadreturns. On error the offset stays at the start of the bad value.ByteArrayDecoderPlain::readreturnsOk(0)when there is nothing to read (to_read == 0), before it estimates the reservation. It already returnedOk(0)for that case. The column reader compares the count with the number of values the levels asked for, so a page that claims no values while the levels want one now fails with "insufficient values read from column" instead of panicking.ByteViewArrayDecoderPlain::skiphas the identical loop and gets the same check. It didn't panic, because the viewreadbounds-checks first, but on a corrupt pageskipreturnedOk.Are these changes tested?
Yes.
skippast the end of the page, for both plain decodersreadwith no remaining valuesreadandskip: a value longer than the page, au32::MAXlength, and a length prefix cut to 1-3 bytes. Each case checks forEOF, that earlier values are kept, and that the offset stays at the bad value.arrow_reader/tests/column_reader.rspatch bytes of a written file and read it withParquetRecordBatchReader. Both panicked before this change.Are there any significant user-facing changes?
No.