File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 11# Changelog
22
33## Unreleased
4+ - Guarded ` CompactVector::from_bytes ` against metadata bit-length overflow.
45- Removed the ` anyhow ` dependency in favor of crate-defined errors and updated
56 ` Serializable ` to expose an associated error type for reconstruction.
67- Prevent panic in ` DacsByte::len ` by handling empty level lists gracefully.
Original file line number Diff line number Diff line change @@ -458,7 +458,10 @@ impl Serializable for CompactVector {
458458 }
459459
460460 fn from_bytes ( meta : Self :: Meta , bytes : Bytes ) -> Result < Self > {
461- let data_len = meta. len * meta. width ;
461+ let data_len = meta
462+ . len
463+ . checked_mul ( meta. width )
464+ . ok_or_else ( || Error :: invalid_metadata ( "len * width overflowed" ) ) ?;
462465 let data = BitVectorData :: from_bytes (
463466 BitVectorDataMeta {
464467 len : data_len,
@@ -710,4 +713,16 @@ mod tests {
710713 let other = CompactVector :: from_bytes ( meta, bytes) . unwrap ( ) ;
711714 assert_eq ! ( cv, other) ;
712715 }
716+
717+ #[ test]
718+ fn from_bytes_rejects_overflowing_metadata ( ) {
719+ let cv = CompactVector :: from_slice ( & [ 1 ] ) . unwrap ( ) ;
720+ let mut meta = cv. metadata ( ) ;
721+ meta. len = usize:: MAX ;
722+ meta. width = 2 ;
723+ let bytes = cv. chunks . data . words . clone ( ) . bytes ( ) ;
724+
725+ let err = CompactVector :: from_bytes ( meta, bytes) . unwrap_err ( ) ;
726+ assert ! ( matches!( err, Error :: InvalidMetadata ( _) ) ) ;
727+ }
713728}
You can’t perform that action at this time.
0 commit comments