Skip to content

Commit deb3d67

Browse files
KubuxuStebalien
authored andcommitted
Fix decode of bitfield with trailing run of zeros
Bitfield with trailing run of zeros is non-minimal. We should return an error in these cases. It was found by rle_decode fuzzer. Thanks @Stebalien for better fix. Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 356a835 commit deb3d67

File tree

1 file changed

+45
-0
lines changed
  • ipld/bitfield/src/rleplus

1 file changed

+45
-0
lines changed

ipld/bitfield/src/rleplus/mod.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ impl BitField {
183183
next_value = !next_value;
184184
}
185185

186+
// next_value equal true means we just read a run of zeros
187+
// which means that there is a trailing run of zeros
188+
if next_value {
189+
return Err(Error::NotMinimal);
190+
}
191+
186192
Ok(Self {
187193
ranges,
188194
..Default::default()
@@ -413,6 +419,45 @@ mod tests {
413419
],
414420
Err(Error::NotMinimal),
415421
),
422+
// tailing runs of zeros
423+
(
424+
vec![
425+
0, 0, // version
426+
0, // starts with 0
427+
1, // run of one
428+
],
429+
Err(Error::NotMinimal),
430+
),
431+
(
432+
vec![
433+
0, 0, // version
434+
0, // starts with 0
435+
0, 1, // fits into 4 bits
436+
0, 0, 1, 0,
437+
],
438+
Err(Error::NotMinimal),
439+
),
440+
(
441+
vec![
442+
0, 0, // version
443+
1, // starts with 1
444+
0, 1, // fits into 4 bits
445+
0, 0, 1, 0, // 2
446+
1, // trailing run of zeros
447+
],
448+
Err(Error::NotMinimal),
449+
),
450+
(
451+
vec![
452+
0, 0, // version
453+
0, // starts with 1
454+
1, //run of one
455+
0, 1, // fits into 4 bits
456+
0, 0, 1, 0, // 2
457+
0, 1, 0, 0, 1, 0, // 2 trailing zeros
458+
],
459+
Err(Error::NotMinimal),
460+
),
416461
]
417462
.into_iter()
418463
.enumerate()

0 commit comments

Comments
 (0)