Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
- Guarded `CompactVector::from_bytes` against metadata bit-length overflow.
- Removed the `anyhow` dependency in favor of crate-defined errors and updated
`Serializable` to expose an associated error type for reconstruction.
- Prevent panic in `DacsByte::len` by handling empty level lists gracefully.
Expand Down
17 changes: 16 additions & 1 deletion src/int_vectors/compact_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,10 @@ impl Serializable for CompactVector {
}

fn from_bytes(meta: Self::Meta, bytes: Bytes) -> Result<Self> {
let data_len = meta.len * meta.width;
let data_len = meta
.len
.checked_mul(meta.width)
.ok_or_else(|| Error::invalid_metadata("len * width overflowed"))?;
let data = BitVectorData::from_bytes(
BitVectorDataMeta {
len: data_len,
Expand Down Expand Up @@ -710,4 +713,16 @@ mod tests {
let other = CompactVector::from_bytes(meta, bytes).unwrap();
assert_eq!(cv, other);
}

#[test]
fn from_bytes_rejects_overflowing_metadata() {
let cv = CompactVector::from_slice(&[1]).unwrap();
let mut meta = cv.metadata();
meta.len = usize::MAX;
meta.width = 2;
let bytes = cv.chunks.data.words.clone().bytes();

let err = CompactVector::from_bytes(meta, bytes).unwrap_err();
assert!(matches!(err, Error::InvalidMetadata(_)));
}
}