Skip to content

Commit bdcbbb1

Browse files
Merge branch 'main' into codex/update-bitvectordata-from_bytes-validation
2 parents 7b6467c + 8a351c9 commit bdcbbb1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44
- Added metadata validation in `BitVectorData::from_bytes` to reject lengths
55
exceeding the stored capacity and covered the case with a regression test.
6+
- Guarded `CompactVector::from_bytes` against metadata bit-length overflow.
67
- Removed the `anyhow` dependency in favor of crate-defined errors and updated
78
`Serializable` to expose an associated error type for reconstruction.
89
- Prevent panic in `DacsByte::len` by handling empty level lists gracefully.

src/int_vectors/compact_vector.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)