Skip to content

Commit cd4dddb

Browse files
Fix Bitfield from_bytes empty vec bug
Credit to @kirk-baird for finding the bug with the fuzzer. Co-authored-by: Kirk Baird <baird.k@outlook.com>
1 parent e21d3fe commit cd4dddb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

eth2/utils/ssz_types/src/bitfield.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ impl<N: Unsigned + Clone> Bitfield<Variable<N>> {
163163
pub fn from_bytes(bytes: Vec<u8>) -> Result<Self, Error> {
164164
let mut initial_bitfield: Bitfield<Variable<N>> = {
165165
let num_bits = bytes.len() * 8;
166-
Bitfield::from_raw_bytes(bytes, num_bits)
167-
.expect("Must have adequate bytes for bit count.")
166+
Bitfield::from_raw_bytes(bytes, num_bits)?
168167
};
169168

170169
let len = initial_bitfield
@@ -802,6 +801,11 @@ mod bitlist {
802801

803802
#[test]
804803
fn ssz_decode() {
804+
assert!(BitList0::from_ssz_bytes(&[]).is_err());
805+
assert!(BitList1::from_ssz_bytes(&[]).is_err());
806+
assert!(BitList8::from_ssz_bytes(&[]).is_err());
807+
assert!(BitList16::from_ssz_bytes(&[]).is_err());
808+
805809
assert!(BitList0::from_ssz_bytes(&[0b0000_0000]).is_err());
806810
assert!(BitList1::from_ssz_bytes(&[0b0000_0000, 0b0000_0000]).is_err());
807811
assert!(BitList8::from_ssz_bytes(&[0b0000_0000]).is_err());

0 commit comments

Comments
 (0)