parquet: `DELTA_BYTE_ARRAY` and `DELTA_LENGTH_BYTE_ARRAY` decoders panic in `Bytes::slice` when the lengths block is cut short

Aperta
#12,499 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend, databases

Direzione di ricerca

Read the three unchecked slice sites named in parquet/src/arrow/decoder/delta_byte_array.rs and parquet/src/encodings/decoding.rs, then compare the bounds checks in byte_array.rs and byte_view_array.rs. Start by running the supplied reproducer; done means truncated input returns an error instead of panicking at all three decoder call sites.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
// 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

Lingua principale
Rust
Stelle
3.7k
Fork
1.5k
Merge medio
2g 16h
PR unite (30g)
183

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/arrow-rs

Tutte le issue di apache/arrow-rs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.