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 6767//!
6868#![ no_std]
6969#![ feature( type_alias_impl_trait) ]
70+ #![ feature( cell_filter_map) ]
7071#![ feature( cfg_version) ]
7172#![ cfg_attr(
7273 all( target_family = "bolos" , not( version( "1.64" ) ) ) ,
@@ -348,9 +349,13 @@ impl Block {
348349 unsafe { & * block }
349350 }
350351
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+ }
354359 }
355360
356361 /// Panics if block is illegally short
@@ -382,10 +387,12 @@ impl ByteStream {
382387 }
383388 let chunk_res = self . host_io . get_chunk ( self . current_chunk ) . await ;
384389 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+ }
386394 Err ( _) => reject ( ) . await ,
387395 }
388- //return Ref::map(chunk, |r| &r[self.current_offset + HASH_LEN..]);
389396 }
390397 }
391398
You can’t perform that action at this time.
0 commit comments