parquet: `skip_records` loops forever when a page has fewer repetition levels than it declares

Abierto
#12,495 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@linyiru ya está trabajando en esto.

Desde el 29/11/2026.

  • #12500 de @linyiru — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
30/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
rust

Línea de trabajo

Start at parquet/src/column/reader.rs:312 in skip_records and compare its repetition-level handling with the check in read_records at lines 248-253. Reproduce the malformed page using the provided example and confirm skipping returns the same insufficient-levels error as reading. An open pull request (#12500) is already linked to this issue.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Describe the bug

GenericColumnReader::skip_records does not terminate when a data page of a repeated column declares more values than it has repetition levels. Once the level decoder is exhausted, skip_rep_levels returns (0, 0), nothing in the loop body advances, and while remaining_records != 0 spins at 100% CPU.

read_records handles the same page with an error (Insufficient repetition levels read from column), added in #6232. The skip path did not get the same check.

Through the Arrow reader this is reached by with_offset, with_row_selection and row filters on any list column. A single flipped byte is enough: a byte-flip fuzz of 9 small files (4,000 mutations each, read with with_offset(1)) hung 6 times.

To Reproduce
use std::sync::Arc;

use bytes::Bytes;
use parquet::basic::{Encoding, Repetition, Type as PhysicalType};
use parquet::column::page::{Page, PageMetadata, PageReader};
use parquet::column::reader::{get_column_reader, get_typed_column_reader};
use parquet::data_type::Int32Type;
use parquet::errors::Result;
use parquet::schema::types::{ColumnDescriptor, ColumnPath, Type};

struct OnePage(Option<Page>);

impl Iterator for OnePage {
    type Item = Result<Page>;
    fn next(&mut self) -> Option<Self::Item> {
        self.get_next_page().transpose()
    }
}

impl PageReader for OnePage {
    fn get_next_page(&mut self) -> Result<Option<Page>> {
        Ok(self.0.take())
    }
    fn peek_next_page(&mut self) -> Result<Option<PageMetadata>> {
        Ok(self.0.as_ref().map(|_| PageMetadata {
            num_rows: None,
            num_levels: Some(4),
            is_dict: false,
        }))
    }
    fn skip_next_page(&mut self) -> Result<()> {
        self.0 = None;
        Ok(())
    }
}

fn main() {
    // list<int32> element column: max definition level 1, max repetition level 1
    let leaf = Type::primitive_type_builder("element", PhysicalType::INT32)
        .with_repetition(Repetition::REQUIRED)
        .build()
        .unwrap();
    let path = ColumnPath::new(vec!["list".to_string(), "element".to_string()]);
    let descr = Arc::new(ColumnDescriptor::new(Arc::new(leaf), 1, 1, path));

    // The page declares 4 values, but its repetition levels are one RLE run of 2.
    let page = || {
        let rep_levels = [2 << 1, 0];
        let def_levels = [4 << 1, 1];
        let mut buf = Vec::new();
        buf.extend_from_slice(&rep_levels);
        buf.extend_from_slice(&def_levels);
        buf.extend([10_i32, 20, 30, 40].iter().flat_map(|v| v.to_le_bytes()));
        Page::DataPageV2 {
            buf: Bytes::from(buf),
            num_values: 4,
            encoding: Encoding::PLAIN,
            num_nulls: 0,
            num_rows: 4,
            def_levels_byte_len: 2,
            rep_levels_byte_len: 2,
            is_compressed: false,
            statistics: None,
        }
    };
    let reader = || {
        let pages = Box::new(OnePage(Some(page())));
        get_typed_column_reader::<Int32Type>(get_column_reader(descr.clone(), pages))
    };

    let (mut values, mut def, mut rep) = (vec![], vec![], vec![]);
    let read = reader().read_records(3, Some(&mut def), Some(&mut rep), &mut values);
    println!("read_records(3): {read:?}");

    println!("skip_records(3): ...");
    let skipped = reader().skip_records(3); // never returns
    println!("skip_records(3): {skipped:?}");
}

Output on 60.2.0 and on main (d470f2d54):

read_records(3): Err(General("Insufficient repetition levels read from column"))
skip_records(3): ...

and the process has to be killed.

Expected behavior

skip_records returns the same error as read_records.

Additional context
  • parquet/src/column/reader.rs:312 (skip_records), compare the check at lines 248-253 in read_records.
  • Same class as #1997 and #6232 (#6228), which fixed the read path.
  • Per SECURITY.md this is a bug rather than a vulnerability (an infinite loop on malformed input).

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

Lenguaje dominante
Rust
Estrellas
3.7k
Forks
1.5k
Merge medio
2 d 16 h
PR fusionados (30 d)
183

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/arrow-rs

Todos los issues de apache/arrow-rs

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.