Skip to content

fix(parquet): return error instead of panic on corrupt PLAIN BYTE_ARRAY pages - #12179

Merged
viirya merged 1 commit into
apache:mainfrom
viirya:fix-plain-byte-array-corrupt-panics
Nov 12, 2026
Merged

viirya merged 1 commit into
apache:mainfrom
viirya:fix-plain-byte-array-corrupt-panics

Conversation

@viirya

@viirya viirya commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

ByteArrayDecoderPlain can panic on corrupt PLAIN BYTE_ARRAY pages, and both panics can be reached from ParquetRecordBatchReader.

  • skip moves past the end of the page without an error. The next read on that page then underflows buf.len() - offset.
  • read divides by max_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::skip checks each value's end offset against the page, using checked_add, and returns the same ParquetError::EOF("eof decoding byte array") that read returns. On error the offset stays at the start of the bad value.
  • ByteArrayDecoderPlain::read returns Ok(0) when there is nothing to read (to_read == 0), before it estimates the reservation. It already returned Ok(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::skip has the identical loop and gets the same check. It didn't panic, because the view read bounds-checks first, but on a corrupt page skip returned Ok.

Are these changes tested?

Yes.

  • Unit tests cover:
    • skip past the end of the page, for both plain decoders
    • read with no remaining values
    • a truncation table for read and skip: a value longer than the page, a u32::MAX length, and a length prefix cut to 1-3 bytes. Each case checks for EOF, that earlier values are kept, and that the offset stays at the bad value.
  • Two reader tests in arrow_reader/tests/column_reader.rs patch bytes of a written file and read it with ParquetRecordBatchReader. Both panicked before this change.

Are there any significant user-facing changes?

No.

…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]>
@boring-cyborg boring-cyborg Bot added the parquet parquet crate label Nov 10, 2026
@viirya
viirya requested a review from Jefffrey November 11, 2026 01:54
@Jefffrey Jefffrey added the bug Squash those bugs label Nov 12, 2026
@viirya
viirya added this pull request to the merge queue Nov 12, 2026
@viirya

viirya commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Thanks @Jefffrey !

Merged via the queue into apache:main with commit 23ce7c3 Nov 12, 2026
20 checks passed
@viirya
viirya deleted the fix-plain-byte-array-corrupt-panics branch November 12, 2026 06:25
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.
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.

Reading a corrupt PLAIN BYTE_ARRAY page can panic in ByteArrayDecoderPlain

2 participants