Repository navigation
Use checked arithmetic when decoding row-encoding options metadata - #11395
Conversation
The declared field count in RowEncodingOptions metadata is read from the input, so computing the expected length as 4 + 2 * n could overflow usize on 32-bit targets before the length check. Use checked arithmetic and return an error instead. Fixes vortex-data#11393 Signed-off-by: Vincent <1729065730@qq.com>
Merging this PR will improve performance by 16.19%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
Summary
deserialize_row_encoding_optionsreads au32field count from the metadata and computed the expected length as4 + 2 * nbefore validating the input length. On 32-bit targets a count like0x8000_0000overflowsusizethere, which panics in checked builds instead of returning an error.Changes
checked_mul/checked_addand bail with an error if it overflows, so oversized counts are rejected the same way as other malformed metadata.vortex-row/src/options.rsfor a serialize/deserialize roundtrip, for huge declared field counts (0x8000_0000andu32::MAX), and for truncated metadata. On a 64-bit host the huge counts are rejected by the length check; the overflow itself only applies to 32-bit targets.Tested with
cargo test -p vortex-rowandcargo clippy -p vortex-row --all-targets -- -D warnings.AI assistance: this change was prepared with help from an AI coding assistant (agentic), and reviewed and submitted by me.