Repository navigation
Closed
Closed
Copy link
Labels
bugSquash those bugs
Description
Describe the bug
ByteArrayDecoderPlain (parquet/src/arrow/array_reader/byte_array.rs) can panic on corrupt PLAIN BYTE_ARRAY data instead of returning an error. Both cases can be reached through ParquetRecordBatchReader.
skipdoesn't check value lengths against the page. It advancesself.offsetby4 + lenand returnsOk, even when that goes past the end of the buffer. The nextreadon the page then computesself.buf.len() - self.offset. That overflows: debug builds panic with "attempt to subtract with overflow", and release builds wrap and then panic with "capacity overflow" inreserve.readalready returnsParquetError::EOF("eof decoding byte array")for the same input.readdivides bymax_remaining_valuesto estimate how many bytes to reserve. On a DataPage v2 whose header says every value is null (num_nulls == num_values),max_remaining_valuesis 0. If the definition levels still mark a value as non-null and the value buffer isn't empty,readpanics with "attempt to divide by zero". A dictionary page withnum_values = 0and a non-empty buffer reaches the same division throughset_dict.
To Reproduce
Case 1, skip past the end of the page:
- Write a required
Utf8column["first", "second", "third"]withArrowWriter, using PLAIN encoding and no dictionary. - Change the 4-byte length prefix of
"first"from5to0xFF05. - Read it with
ParquetRecordBatchReaderBuilder, using aRowSelectionofskip(1), select(2)andRowSelectionPolicy::Selectors.
Case 2, all-null v2 page with a value:
- Write a nullable
Utf8column[Some("a"), None]withWriterVersion::PARQUET_2_0and PLAIN encoding. - Change
num_nullsin theDataPageHeaderV2from 1 to 2. - Read the file.
Directly against the decoder:
// Case 1
let mut d = ByteArrayDecoderPlain::new(Bytes::from_static(&[0xFF, 0xFF, 0, 0, b'a']), 2, Some(2), false);
assert_eq!(d.skip(1).unwrap(), 1); // offset is now 65539, past the 5-byte page
d.read(&mut OffsetBuffer::<i32>::with_capacity(0), 1); // panics
// Case 2
let mut d = ByteArrayDecoderPlain::new(Bytes::from_static(&[1, 0, 0, 0, b'a']), 0, Some(0), false);
d.read(&mut OffsetBuffer::<i32>::with_capacity(0), 1); // panics: divide by zeroExpected behavior
Both cases return a ParquetError instead of panicking.
Additional context
This belongs with the other "return an error instead of a panic on a corrupt Parquet file" fixes, e.g. #12108 for DELTA_BYTE_ARRAY. ByteViewArrayDecoderPlain::skip has the same unchecked skip. It doesn't panic, because its read checks start_offset > buf_len, but on a corrupt page skip still returns Ok.
Metadata
Metadata
Assignees
Labels
bugSquash those bugs
Activity
fix(parquet): return error instead of panic on corrupt PLAIN BYTE_ARR…