linyiru opened a new issue, #12499:
URL: https://github.com/apache/arrow-rs/issues/12499

   ### Describe the bug
   
   The byte array delta decoders decode the lengths with `DeltaBitPackDecoder` 
and then slice the page at `get_offset()` to find what follows. Once all values 
are read, `get_offset()` reports the end of the current block as its miniblock 
bit widths declare it. On a truncated or corrupt page that is past the end of 
the buffer, and `Bytes::slice` panics:
   
   ```
   thread 'main' panicked at bytes-1.12.2/src/bytes.rs:374:28:
   range start must not be greater than end: 51 <= 17
   ```
   
   Three call sites slice without checking:
   
   - `parquet/src/arrow/decoder/delta_byte_array.rs:32` (Arrow reader)
   - `parquet/src/encodings/decoding.rs:979` (`DeltaLengthByteArrayDecoder`)
   - `parquet/src/encodings/decoding.rs:1130` (`DeltaByteArrayDecoder`)
   
   Found by byte-flip fuzzing; one flipped byte in a `DELTA_BYTE_ARRAY` page of 
a zstd v2 file is enough.
   
   ### To Reproduce
   
   ```rust
   // parquet = { version = "60.2.0", features = ["experimental"] }
   use bytes::Bytes;
   use parquet::data_type::ByteArrayType;
   use parquet::encodings::decoding::{Decoder, DeltaByteArrayDecoder};
   
   fn main() {
       // DELTA_BINARY_PACKED prefix lengths [0, 300, 0]: block size 128, 4 
miniblocks,
       // 3 values, first value 0, min delta -300, miniblock bit widths [10, 0, 
0, 0].
       // The miniblock should be 40 bytes (32 values of 10 bits); the page 
ends after 6.
       let page = Bytes::from_static(&[128, 1, 4, 3, 0, 215, 4, 10, 0, 0, 0, 
88, 2, 0, 0, 0, 0]);
       let mut decoder = DeltaByteArrayDecoder::<ByteArrayType>::new();
       println!("{:?}", decoder.set_data(page, 3));
   }
   ```
   
   Panics on 60.2.0 and on main (d470f2d54).
   
   ### Expected behavior
   
   An error, as for the other malformed length streams (#12290 / #12324).
   
   ### Additional context
   
   `byte_array.rs` and `byte_view_array.rs` already compare 
`len_decoder.get_offset()` with `data.len()` before using it.
   
   This report was prepared with AI assistance (Claude Code). The reproduction 
was run against 60.2.0 and main.
   
   ### Willingness to contribute
   
   I plan to contribute a fix for this bug independently
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to