arrow-avro: sync `Reader` hangs on a block with bytes after its last record, and repeats errors forever
I maintainer di solito rispondono entro 1 giorno
@dayan02dev ci sta già lavorando.
Dal 28/11/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Describe the bug
The OCF Reader (ReaderBuilder::build) tracks progress through a block by byte position instead of by the block's record count, and it keeps going after an error:
- If a block's data has bytes left after its declared records,
next()loops forever at 100% CPU. - After a decode error, every later
next()returns the same error again, so the iterator never ends. - A block whose records take zero bytes (for example a record whose only field is
null) is skipped, so its rows are lost.
To Reproduce
Dependencies: arrow-avro, arrow-schema (60.2.0 or main).
use std::io::Cursor;
use arrow_avro::reader::ReaderBuilder;
use arrow_avro::writer::AvroWriter;
use arrow_schema::{DataType, Field, Schema};
/// An OCF file with one column of `data_type` and one data block holding `count`
/// records encoded in `payload`.
fn ocf(data_type: DataType, count: u8, payload: &[u8]) -> Vec<u8> {
let schema = Schema::new(vec![Field::new("a", data_type, false)]);
let mut writer = AvroWriter::new(Vec::new(), schema).unwrap();
writer.finish().unwrap();
let mut file = writer.into_inner();
let sync = file[file.len() - 16..].to_vec();
// zig-zag encoded block count and block size
file.extend([count * 2, payload.len() as u8 * 2]);
file.extend_from_slice(payload);
file.extend_from_slice(&sync);
file
}
fn main() {
// Two `null` records, which take zero bytes each.
let reader = ReaderBuilder::new()
.build(Cursor::new(ocf(DataType::Null, 2, &[])))
.unwrap();
let rows: usize = reader.map(|batch| batch.unwrap().num_rows()).sum();
println!("zero-byte records: {rows} rows");
// A block that declares two int records but holds one.
let reader = ReaderBuilder::new()
.build(Cursor::new(ocf(DataType::Int32, 2, &[0x02])))
.unwrap();
for item in reader.take(3) {
println!("missing record: {:?}", item.map(|batch| batch.num_rows()));
}
// A block that declares one int record (the value 1) followed by one extra byte.
let reader = ReaderBuilder::new()
.build(Cursor::new(ocf(DataType::Int32, 1, &[0x02, 0x00])))
.unwrap();
for item in reader {
println!("trailing byte: {:?}", item.map(|batch| batch.num_rows()));
}
println!("done");
}
Output on main, after which the program spins until killed:
zero-byte records: 0 rows
missing record: Err(AvroError("Parser error: bad varint"))
missing record: Err(AvroError("Parser error: bad varint"))
missing record: Err(AvroError("Parser error: bad varint"))
Expected behavior
zero-byte records: 2 rows
missing record: Err(AvroError("Parser error: bad varint"))
trailing byte: Ok(1)
done
This is what AsyncAvroFileReader returns for the same bytes: it moves to the next block once the block's record count is used up, and stops after the first error (arrow-avro/src/reader/async_reader/mod.rs:472-493).
Additional context
Affects every published release from 56.2.1 through 60.2.0, and main (the loop came in with #8100).
Cause: Reader::read (arrow-avro/src/reader/mod.rs:1401-1439) treats a block as done only when its byte cursor reaches the end of the block data, so leftover bytes leave it calling decode_block with a record count of 0 forever, and a block with no bytes is skipped; Reader::next (:1448-1450) never sets finished after an error.
The Avro spec doesn't say what a reader should do with bytes left in a block. Java's DataFileStream fails with "Block read partially, the data may be corrupt" (AVRO-4006); matching the async reader instead keeps the two arrow-avro readers consistent.
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
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/arrow-rs
-
parquet: `ArrowWriter::try_new` panics on a schema with a Union field instead of returning an errorAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
`RunArray::try_new` rejects run ends whose null buffer has no nullsForse già presa @Surajsuthar l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
apache/arrow-rs#12427 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Variant] `variant_get` string and binary cast errors show Rust builder type namesForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 61/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di apache/arrow-rs
Issue simili
-
area:ui effort:medium enhancement P7 source:agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
marketing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
machine rename accepts a label already used by another machine, making --machine <label> ambiguousApertamaintainer-needed p2 remote triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug help wanted ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
userFRM/egui-charts#4605 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno