@@ -24,6 +24,15 @@ impl Sanitize for Uncompressed {
24
24
if self . num >= MAX_SLOTS_PER_ENTRY {
25
25
return Err ( SanitizeError :: ValueOutOfBounds ) ;
26
26
}
27
+ if self . slots . len ( ) % 8 != 0 {
28
+ // Uncompressed::new() ensures the length is always a multiple of 8
29
+ return Err ( SanitizeError :: ValueOutOfBounds ) ;
30
+ }
31
+ if self . slots . len ( ) != self . slots . capacity ( ) {
32
+ // A BitVec<u8> with a length that's a multiple of 8 will always have len() equal to
33
+ // capacity(), assuming no bit manipulation
34
+ return Err ( SanitizeError :: ValueOutOfBounds ) ;
35
+ }
27
36
Ok ( ( ) )
28
37
}
29
38
}
@@ -132,7 +141,7 @@ impl Uncompressed {
132
141
if * s < self . first_slot {
133
142
return i;
134
143
}
135
- if * s - self . first_slot >= self . slots . capacity ( ) {
144
+ if * s - self . first_slot >= self . slots . len ( ) {
136
145
return i;
137
146
}
138
147
self . slots . set ( * s - self . first_slot , true ) ;
@@ -393,6 +402,14 @@ mod tests {
393
402
o. num = MAX_SLOTS_PER_ENTRY ;
394
403
assert_eq ! ( o. sanitize( ) , Err ( SanitizeError :: ValueOutOfBounds ) ) ;
395
404
405
+ let mut o = slots. clone ( ) ;
406
+ o. slots = BitVec :: new_fill ( false , 7 ) ; // Length not a multiple of 8
407
+ assert_eq ! ( o. sanitize( ) , Err ( SanitizeError :: ValueOutOfBounds ) ) ;
408
+
409
+ let mut o = slots. clone ( ) ;
410
+ o. slots = BitVec :: with_capacity ( 8 ) ; // capacity() not equal to len()
411
+ assert_eq ! ( o. sanitize( ) , Err ( SanitizeError :: ValueOutOfBounds ) ) ;
412
+
396
413
let compressed = Flate2 :: deflate ( slots) . unwrap ( ) ;
397
414
assert ! ( compressed. sanitize( ) . is_ok( ) ) ;
398
415
0 commit comments