File tree Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Expand file tree Collapse file tree 1 file changed +12
-5
lines changed Original file line number Diff line number Diff line change 67
67
//!
68
68
#![ no_std]
69
69
#![ feature( type_alias_impl_trait) ]
70
+ #![ feature( cell_filter_map) ]
70
71
#![ feature( cfg_version) ]
71
72
#![ cfg_attr(
72
73
all( target_family = "bolos" , not( version( "1.64" ) ) ) ,
@@ -348,9 +349,13 @@ impl Block {
348
349
unsafe { & * block }
349
350
}
350
351
351
- pub fn from_raw_slice ( block : & [ u8 ] ) -> & Self {
352
- let block2 = block as * const [ u8 ] as * const Block ;
353
- unsafe { & * block2 }
352
+ pub fn from_raw_slice_opt ( block : & [ u8 ] ) -> Option < & Self > {
353
+ if block. len ( ) >= HASH_LEN {
354
+ let block2 = block as * const [ u8 ] as * const Block ;
355
+ Some ( unsafe { & * block2 } )
356
+ } else {
357
+ None
358
+ }
354
359
}
355
360
356
361
/// Panics if block is illegally short
@@ -382,10 +387,12 @@ impl ByteStream {
382
387
}
383
388
let chunk_res = self . host_io . get_chunk ( self . current_chunk ) . await ;
384
389
match chunk_res {
385
- Ok ( a) => Ref :: map ( a, Block :: from_raw_slice) ,
390
+ Ok ( a) => match Ref :: filter_map ( a, Block :: from_raw_slice_opt) {
391
+ Ok ( r) => r,
392
+ Err ( _) => reject ( ) . await ,
393
+ }
386
394
Err ( _) => reject ( ) . await ,
387
395
}
388
- //return Ref::map(chunk, |r| &r[self.current_offset + HASH_LEN..]);
389
396
}
390
397
}
391
398
You can’t perform that action at this time.
0 commit comments