birkskyum opened a new issue, #12471:
URL: https://github.com/apache/arrow-rs/issues/12471
### Describe the bug
A dictionary page's `num_values` sizes the dictionary before any value is
decoded. In a 120-byte file, an 8-byte INT64 dictionary page that declares
`i32::MAX` values asks for 16 GiB in `DictDecoder::set_dict`
(`encodings/decoding.rs:366`). Under a memory limit the process aborts (`memory
allocation of 17179869176 bytes failed`) or is OOM-killed, and `catch_unwind`
can't contain that. Without a limit, 16 GiB is zero-filled before the read
returns an EOF error. A BYTE_ARRAY column allocates the same way in
`arrow/array_reader/byte_array.rs:373` (8 GiB) and in
`ViewBuffer::with_capacity` (`arrow/array_reader/byte_view_array.rs:167`, 32
GiB). This happens on 60.1.0, 60.2.0 and main (8befa3cd89).
### To Reproduce
`cargo new repro` with `parquet = "60.2.0"`, then `cargo build --release`
and on Linux `(ulimit -v 4194304; target/release/repro)`:
```rust
use parquet::arrow::arrow_reader::ParquetRecordBatchReaderBuilder;
fn main() {
// 120 bytes, one INT64 row. Its 8-byte dictionary page declares
i32::MAX values.
let hex =
"504152311504151015104c15feffffff0f15001200002a000000000000001500150415042c1502151015061506000000021502192c4806736368656d6115020015042500180163001602191c191c26081c150419350006101918016315001602165a165a263c26080000165a160200003f00000050415231";
let bytes: Vec<u8> = (0..hex.len()).step_by(2)
.map(|i| u8::from_str_radix(&hex[i..i + 2], 16).unwrap()).collect();
std::fs::write("dict.parquet", bytes).unwrap();
let file = std::fs::File::open("dict.parquet").unwrap();
let reader =
ParquetRecordBatchReaderBuilder::try_new(file).unwrap().build().unwrap();
println!("{:?}", reader.collect::<Result<Vec<_>, _>>().map(|b| b.len()));
}
```
### Expected behavior
An `Err`. A dictionary page can't hold more values than its decompressed
size allows at the type's smallest plain width (1 bit for BOOLEAN, 4 bytes for
BYTE_ARRAY). A larger `num_values` can be refused before allocating, as
#12390's SECURITY.md text recommends.
### Additional context
One bad file kills a program that reads Parquet it didn't write, such as a
tiler reading GeoParquet from a URL, or an R or Python session with the reader
built in. #12330 is the same pattern for delta length counts.
--
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]