@@ -13,7 +13,7 @@ pub mod generalized;
13
13
pub use generalized:: * ;
14
14
15
15
pub mod bytessub;
16
- pub use bytessub:: { BytesSlice , BytesSubInput } ;
16
+ pub use bytessub:: BytesSubInput ;
17
17
18
18
#[ cfg( feature = "multipart_inputs" ) ]
19
19
pub mod multi;
@@ -36,13 +36,14 @@ use std::{fs::File, hash::Hash, io::Read, path::Path};
36
36
use libafl_bolts:: fs:: write_file_atomic;
37
37
use libafl_bolts:: {
38
38
ownedref:: { OwnedMutSlice , OwnedSlice } ,
39
+ subrange:: { PartialSubRangeSlice , SubRangeSlice , SubRangeSliceMut } ,
39
40
Error , HasLen ,
40
41
} ;
41
42
#[ cfg( feature = "nautilus" ) ]
42
43
pub use nautilus:: * ;
43
44
use serde:: { Deserialize , Serialize } ;
44
45
45
- use crate :: { corpus:: CorpusId , inputs :: bytessub :: BytesSliceMut } ;
46
+ use crate :: corpus:: CorpusId ;
46
47
47
48
/// An input for the target
48
49
#[ cfg( not( feature = "std" ) ) ]
@@ -140,35 +141,6 @@ pub struct BytesReader<'a> {
140
141
pos : usize ,
141
142
}
142
143
143
- /// Representation of a partial slice
144
- /// This is used when providing a slice smaller than the expected one.
145
- /// It notably happens when trying to read the end of an input.
146
- #[ derive( Debug ) ]
147
- pub enum PartialBytesSubInput < ' a > {
148
- /// The slice is empty, and thus not kept
149
- Empty ,
150
- /// The slice is strictly smaller than the expected one.
151
- Partial ( BytesSlice < ' a > ) ,
152
- }
153
-
154
- impl < ' a > PartialBytesSubInput < ' a > {
155
- /// Consumes `PartialBytesSubInput` and returns true if it was empty, false otherwise.
156
- #[ must_use]
157
- pub fn empty ( self ) -> bool {
158
- matches ! ( self , PartialBytesSubInput :: Empty )
159
- }
160
-
161
- /// Consumes `PartialBytesSubInput` and returns the partial slice if it was a partial slice, None otherwise.
162
- #[ must_use]
163
- pub fn partial ( self ) -> Option < BytesSlice < ' a > > {
164
- #[ allow( clippy:: match_wildcard_for_single_variants) ]
165
- match self {
166
- PartialBytesSubInput :: Partial ( partial_slice) => Some ( partial_slice) ,
167
- _ => None ,
168
- }
169
- }
170
- }
171
-
172
144
impl < ' a > BytesReader < ' a > {
173
145
/// Create a new [`BytesReader`].
174
146
/// The position of the reader is initialized to 0.
@@ -184,8 +156,8 @@ impl<'a> BytesReader<'a> {
184
156
/// If the resulting slice would go beyond the end of the parent input, it will be truncated to the length of the parent input.
185
157
/// This function does not provide any feedback on whether the slice was cropped or not.
186
158
#[ must_use]
187
- pub fn next_sub_slice_truncated ( & mut self , limit : usize ) -> BytesSlice < ' a > {
188
- let sub_input = BytesSlice :: with_slice ( self . parent_input , self . pos ..( self . pos + limit) ) ;
159
+ pub fn next_sub_slice_truncated ( & mut self , limit : usize ) -> PartialSubRangeSlice < ' a , u8 > {
160
+ let sub_input = SubRangeSlice :: with_slice ( self . parent_input , self . pos ..( self . pos + limit) ) ;
189
161
190
162
self . pos += sub_input. len ( ) ;
191
163
@@ -201,15 +173,15 @@ impl<'a> BytesReader<'a> {
201
173
pub fn next_sub_input (
202
174
& mut self ,
203
175
limit : usize ,
204
- ) -> Result < BytesSlice < ' a > , PartialBytesSubInput < ' a > > {
176
+ ) -> Result < SubRangeSlice < ' a , u8 > , PartialSubRangeSlice < ' a , u8 > > {
205
177
let slice_to_return = self . next_sub_slice_truncated ( limit) ;
206
178
207
179
let real_len = slice_to_return. len ( ) ;
208
180
209
181
if real_len == 0 {
210
- Err ( PartialBytesSubInput :: Empty )
182
+ Err ( PartialSubRangeSlice :: Empty )
211
183
} else if real_len < limit {
212
- Err ( PartialBytesSubInput :: Partial ( slice_to_return) )
184
+ Err ( PartialSubRangeSlice :: Partial ( slice_to_return) )
213
185
} else {
214
186
Ok ( slice_to_return)
215
187
}
@@ -260,15 +232,15 @@ pub trait HasMutatorBytes: HasLen {
260
232
R : RangeBounds < usize > ;
261
233
262
234
/// Creates a [`BytesSlice`] from this input, that can be used to slice a byte array.
263
- fn sub_bytes < R > ( & self , range : R ) -> BytesSlice
235
+ fn sub_bytes < R > ( & self , range : R ) -> SubRangeSlice < ' a , u8 >
264
236
where
265
237
R : RangeBounds < usize > ,
266
238
{
267
- BytesSlice :: new ( OwnedSlice :: from ( self . bytes ( ) ) , range)
239
+ SubRangeSlice :: new ( OwnedSlice :: from ( self . bytes ( ) ) , range)
268
240
}
269
241
270
242
/// Creates a [`BytesSliceMut`] from this input, that can be used to slice a byte array.
271
- fn sub_bytes_mut < R > ( & mut self , range : R ) -> BytesSliceMut
243
+ fn sub_bytes_mut < R > ( & mut self , range : R ) -> SubRangeSliceMut < ' a , u8 >
272
244
where
273
245
R : RangeBounds < usize > ,
274
246
{
@@ -421,17 +393,17 @@ mod tests {
421
393
let mut bytes_reader = BytesReader :: new ( & bytes_input) ;
422
394
423
395
let bytes_read = bytes_reader. next_sub_slice_truncated ( 2 ) ;
424
- assert_eq ! ( * bytes_read. bytes ( ) , [ 1 , 2 ] ) ;
396
+ assert_eq ! ( * bytes_read. as_slice ( ) , [ 1 , 2 ] ) ;
425
397
426
398
let bytes_read = bytes_reader. next_sub_slice_truncated ( 3 ) ;
427
- assert_eq ! ( * bytes_read. bytes ( ) , [ 3 , 4 , 5 ] ) ;
399
+ assert_eq ! ( * bytes_read. as_slice ( ) , [ 3 , 4 , 5 ] ) ;
428
400
429
401
let bytes_read = bytes_reader. next_sub_slice_truncated ( 8 ) ;
430
- assert_eq ! ( * bytes_read. bytes ( ) , [ 6 , 7 ] ) ;
402
+ assert_eq ! ( * bytes_read. as_slice ( ) , [ 6 , 7 ] ) ;
431
403
432
404
let bytes_read = bytes_reader. next_sub_slice_truncated ( 8 ) ;
433
405
let bytes_read_ref: & [ u8 ] = & [ ] ;
434
- assert_eq ! ( & * bytes_read. bytes ( ) , bytes_read_ref) ;
406
+ assert_eq ! ( & * bytes_read. as_slice ( ) , bytes_read_ref) ;
435
407
}
436
408
437
409
#[ test]
@@ -440,13 +412,16 @@ mod tests {
440
412
let mut bytes_reader = BytesReader :: new ( & bytes_input) ;
441
413
442
414
let bytes_read = bytes_reader. next_sub_input ( 2 ) ;
443
- assert_eq ! ( * bytes_read. unwrap( ) . bytes ( ) , [ 1 , 2 ] ) ;
415
+ assert_eq ! ( * bytes_read. unwrap( ) . as_slice ( ) , [ 1 , 2 ] ) ;
444
416
445
417
let bytes_read = bytes_reader. next_sub_input ( 3 ) ;
446
- assert_eq ! ( * bytes_read. unwrap( ) . bytes ( ) , [ 3 , 4 , 5 ] ) ;
418
+ assert_eq ! ( * bytes_read. unwrap( ) . as_slice ( ) , [ 3 , 4 , 5 ] ) ;
447
419
448
420
let bytes_read = bytes_reader. next_sub_input ( 8 ) ;
449
- assert_eq ! ( * bytes_read. unwrap_err( ) . partial( ) . unwrap( ) . bytes( ) , [ 6 , 7 ] ) ;
421
+ assert_eq ! (
422
+ * bytes_read. unwrap_err( ) . partial( ) . unwrap( ) . as_slice( ) ,
423
+ [ 6 , 7 ]
424
+ ) ;
450
425
451
426
let bytes_read = bytes_reader. next_sub_input ( 8 ) ;
452
427
assert ! ( bytes_read. unwrap_err( ) . empty( ) ) ;
0 commit comments