@@ -6,7 +6,7 @@ use libfuzzer_sys::fuzz_target;
6
6
use rand:: { Rng , SeedableRng } ;
7
7
use sequential_storage:: {
8
8
cache:: { CacheImpl , NoCache , PagePointerCache , PageStateCache } ,
9
- mock_flash:: { MockFlashBase , MockFlashError , WriteCountCheck } ,
9
+ mock_flash:: { MockFlashBase , MockFlashError , Operation , WriteCountCheck } ,
10
10
Error ,
11
11
} ;
12
12
use std:: { collections:: VecDeque , fmt:: Debug , ops:: Range } ;
@@ -79,7 +79,9 @@ fn fuzz(ops: Input, mut cache: impl CacheImpl + Debug) {
79
79
80
80
match & mut op {
81
81
Op :: Push ( op) => {
82
- let val: Vec < u8 > = ( 0 ..op. value_len as usize % 16 ) . map ( |_| rng. gen ( ) ) . collect ( ) ;
82
+ let val: Vec < u8 > = ( 0 ..op. value_len as usize % 16 )
83
+ . map ( |_| rng. random ( ) )
84
+ . collect ( ) ;
83
85
84
86
let max_fit = match block_on ( sequential_storage:: queue:: find_max_fit (
85
87
& mut flash,
@@ -124,7 +126,7 @@ fn fuzz(ops: Input, mut cache: impl CacheImpl + Debug) {
124
126
}
125
127
}
126
128
Err ( Error :: Storage {
127
- value : MockFlashError :: EarlyShutoff ( address) ,
129
+ value : MockFlashError :: EarlyShutoff ( address, _ ) ,
128
130
backtrace : _backtrace,
129
131
} ) => {
130
132
// We need to check if it managed to write
@@ -164,17 +166,19 @@ fn fuzz(ops: Input, mut cache: impl CacheImpl + Debug) {
164
166
) ;
165
167
}
166
168
Err ( Error :: Storage {
167
- value : MockFlashError :: EarlyShutoff ( address) ,
169
+ value : MockFlashError :: EarlyShutoff ( address, operation ) ,
168
170
backtrace : _backtrace,
169
171
} ) => {
170
172
#[ cfg( fuzzing_repro) ]
171
173
eprintln ! (
172
174
"Early shutoff when popping (single)! Originated from:\n {_backtrace:#}"
173
175
) ;
174
176
175
- if !matches ! ( block_on( flash. get_item_presence( address) ) , Some ( true ) ) {
176
- // The item is no longer readable here
177
- order. pop_front ( ) ;
177
+ if operation != Operation :: Erase {
178
+ if !matches ! ( block_on( flash. get_item_presence( address) ) , Some ( true ) ) {
179
+ // The item is no longer readable here
180
+ order. pop_front ( ) ;
181
+ }
178
182
}
179
183
}
180
184
Err ( Error :: Corrupted {
@@ -202,6 +206,17 @@ fn fuzz(ops: Input, mut cache: impl CacheImpl + Debug) {
202
206
order. front( ) . as_ref( ) . map( |target| target. as_slice( ) )
203
207
) ;
204
208
}
209
+ Err ( Error :: Storage {
210
+ value : MockFlashError :: EarlyShutoff ( _, Operation :: Erase ) ,
211
+ backtrace : _backtrace,
212
+ } ) => {
213
+ #[ cfg( fuzzing_repro) ]
214
+ eprintln ! (
215
+ "Early shutoff when getting next iterator entry! Originated from:\n {_backtrace:#}"
216
+ ) ;
217
+
218
+ break ;
219
+ }
205
220
Err ( Error :: Corrupted {
206
221
backtrace : _backtrace,
207
222
} ) => {
@@ -243,6 +258,9 @@ fn fuzz(ops: Input, mut cache: impl CacheImpl + Debug) {
243
258
) ;
244
259
245
260
if * do_pop {
261
+ #[ cfg( fuzzing_repro) ]
262
+ eprintln ! ( "Popping item at address: {}" , value. address( ) ) ;
263
+
246
264
let popped = block_on ( value. pop ( ) ) ;
247
265
248
266
match popped {
@@ -268,20 +286,22 @@ fn fuzz(ops: Input, mut cache: impl CacheImpl + Debug) {
268
286
panic ! ( "Corrupted!" ) ;
269
287
}
270
288
Err ( Error :: Storage {
271
- value : MockFlashError :: EarlyShutoff ( address) ,
289
+ value : MockFlashError :: EarlyShutoff ( address, operation ) ,
272
290
backtrace : _backtrace,
273
291
} ) => {
274
292
#[ cfg( fuzzing_repro) ]
275
293
eprintln ! (
276
294
"Early shutoff when popping iterator entry! Originated from:\n {_backtrace:#}"
277
295
) ;
278
296
279
- if !matches ! (
280
- block_on( flash. get_item_presence( address) ) ,
281
- Some ( true )
282
- ) {
283
- // The item is no longer readable here
284
- order. remove ( i - popped_items) . unwrap ( ) ;
297
+ if operation != Operation :: Erase {
298
+ if !matches ! (
299
+ block_on( flash. get_item_presence( address) ) ,
300
+ Some ( true )
301
+ ) {
302
+ // The item is no longer readable here
303
+ order. remove ( i - popped_items) . unwrap ( ) ;
304
+ }
285
305
}
286
306
287
307
break ;
@@ -293,6 +313,25 @@ fn fuzz(ops: Input, mut cache: impl CacheImpl + Debug) {
293
313
Ok ( None ) => {
294
314
assert_eq ! ( None , order. get( i as usize - popped_items) ) ;
295
315
}
316
+ Err ( Error :: Storage {
317
+ value : MockFlashError :: EarlyShutoff ( address, operation) ,
318
+ backtrace : _backtrace,
319
+ } ) => {
320
+ #[ cfg( fuzzing_repro) ]
321
+ eprintln ! (
322
+ "Early shutoff when getting next iterator entry! Originated from:\n {_backtrace:#}"
323
+ ) ;
324
+
325
+ if operation != Operation :: Erase {
326
+ if !matches ! ( block_on( flash. get_item_presence( address) ) , Some ( true ) )
327
+ {
328
+ // The item is no longer readable here
329
+ order. remove ( i - popped_items) . unwrap ( ) ;
330
+ }
331
+ }
332
+
333
+ break ;
334
+ }
296
335
Err ( Error :: Corrupted {
297
336
backtrace : _backtrace,
298
337
} ) => {
@@ -302,7 +341,7 @@ fn fuzz(ops: Input, mut cache: impl CacheImpl + Debug) {
302
341
) ;
303
342
panic ! ( "Corrupted!" ) ;
304
343
}
305
- Err ( e) => panic ! ( "Error iterating queue: {e:?}" ) ,
344
+ Err ( e) => panic ! ( "Error iterating queue: {e:# ?}" ) ,
306
345
}
307
346
}
308
347
}
0 commit comments