viirya opened a new pull request, #12474: URL: https://github.com/apache/arrow-rs/pull/12474
# Which issue does this PR close? - Closes #12473. # Rationale for this change Corrupt RLE run headers or DELTA_BINARY_PACKED headers in page data make `BitReader::get_vlq_int` panic: an `assert!` fires in release builds and a shift overflow fires in debug builds. The reader should return a `ParquetError` instead. # What changes are included in this PR? - `BitReader::get_vlq_int` and `get_zigzag_vlq_int` now return `Result<Option<i64>>` instead of `Option<i64>`. `Ok(None)` still means the buffer ran out. An encoding longer than `MAX_VLQ_BYTE_LEN` bytes, or a 10th byte that would overflow 64 bits, now returns an error. On error the reader is not advanced. - A single-byte fast path keeps the common case (short RLE run headers) cheap. The loop now accumulates into a `u64` with a shift of at most 63. - `RleDecoder::reload` and `DeltaBitPackDecoder` propagate the error with `?`. Before this change, mapping a malformed value to `None` would have made `RleDecoder` treat it as a normal end of data. - The thrift `read_vlq` now returns `ThriftProtocolError::IntegerOverflow` for an overlong or overflowing varint instead of silently wrapping. # Are these changes tested? Yes. New unit tests cover: - `BitReader`: an overlong varint (10 and 11+ continuation bytes), a 10th byte that overflows, `u64::MAX` (the largest valid value), and truncated buffers. - `RleDecoder`: a corrupt header in `set_data`, and a corrupt header after a valid run in `get_batch`. - `DeltaBitPackDecoder`: a corrupt `block_size`, an overflowing `first_value`, and a corrupt block `min_delta`. All `cargo test -p parquet` tests pass. # Are there any user-facing changes? `BitReader` is public only with the `experimental` feature. For users of that feature, the return types of `BitReader::get_vlq_int` and `BitReader::get_zigzag_vlq_int` change from `Option<i64>` to `Result<Option<i64>>`. Without that feature, the only visible change is that corrupt files now return an error instead of panicking. This pull request and its description were written by Isaac. -- 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]
