Commit d3bfda7
repr: saturate array-cardinality product to avoid multiply overflow (#37177)
`RowPacker::push_array_with_unchecked` and `push_array_with_row_major`
compute an array's expected cardinality as the product of its dimension
lengths and compare it against the actual number of elements pushed. The
product was an unchecked `usize` multiply (`dims.iter()...product()` /
`cardinality *= dim.length`), so dimension lengths whose product exceeds
`usize::MAX` overflowed.
Under overflow checks (debug, and the cargo-fuzz build) this panics; in
release it silently wraps, and a wrapped value can even spuriously match
the actual element count — accepting a corrupt array (e.g. dims claiming
`[2^32, 2^32]` wrap to a cardinality of 0, matching an empty element
list). This is reachable from `Row::decode` over an attacker- or
corruption-supplied `ProtoRow`, since the proto array dimensions are not
otherwise bounded.
Saturate the product to `usize::MAX` instead. An overflowing cardinality
is impossibly large — no array can hold that many elements — so it never
equals the real element count and the existing check rejects it as
`WrongCardinality`, turning the panic/silent-wrap into a clean error on
both build profiles.
Found by the `repr::row_codec_roundtrip` cargo-fuzz target in
#36982
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 66475d1 commit d3bfda7
1 file changed
Lines changed: 45 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2559 | 2559 | | |
2560 | 2560 | | |
2561 | 2561 | | |
2562 | | - | |
| 2562 | + | |
| 2563 | + | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
2563 | 2573 | | |
2564 | 2574 | | |
2565 | 2575 | | |
| |||
2602 | 2612 | | |
2603 | 2613 | | |
2604 | 2614 | | |
2605 | | - | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
2606 | 2619 | | |
2607 | 2620 | | |
2608 | 2621 | | |
| |||
3784 | 3797 | | |
3785 | 3798 | | |
3786 | 3799 | | |
| 3800 | + | |
| 3801 | + | |
| 3802 | + | |
| 3803 | + | |
| 3804 | + | |
| 3805 | + | |
| 3806 | + | |
| 3807 | + | |
| 3808 | + | |
| 3809 | + | |
| 3810 | + | |
| 3811 | + | |
| 3812 | + | |
| 3813 | + | |
| 3814 | + | |
| 3815 | + | |
| 3816 | + | |
| 3817 | + | |
| 3818 | + | |
| 3819 | + | |
| 3820 | + | |
| 3821 | + | |
| 3822 | + | |
| 3823 | + | |
| 3824 | + | |
| 3825 | + | |
| 3826 | + | |
| 3827 | + | |
| 3828 | + | |
| 3829 | + | |
3787 | 3830 | | |
3788 | 3831 | | |
3789 | 3832 | | |
| |||
0 commit comments