@@ -67,10 +67,10 @@ impl PEInfo {
6767 log_then_return ! ( "unsupported PE file, not an executable image" )
6868 }
6969
70- let optional_header = pe
71- . header
72- . optional_header
73- . expect ( "unsupported PE file, missing optional header entry" ) ;
70+ let optional_header = match pe . header . optional_header {
71+ Some ( optional_header ) => optional_header ,
72+ None => log_then_return ! ( "unsupported PE file, no optional header found" ) ,
73+ } ;
7474
7575 // check that the PE file was built with the option /DYNAMICBASE
7676
@@ -117,10 +117,10 @@ impl PEInfo {
117117 // we are going to take care of the data section
118118 if name == ".data" {
119119 // Make sure we fail if we enter this block more than once
120- assert_eq ! (
121- data_section_additional_bytes, 0 ,
122- "Hyperlight currently only supports one .data section"
123- ) ;
120+
121+ if data_section_additional_bytes > 0 {
122+ log_then_return ! ( "Hyperlight currently only supports one .data section" )
123+ }
124124
125125 data_section_raw_pointer = section. pointer_to_raw_data ;
126126 data_section_additional_bytes = virtual_size - raw_size;
@@ -251,8 +251,7 @@ impl PEInfo {
251251 }
252252
253253 cur. set_position ( patch. offset as u64 ) ;
254- cur. write_all ( & patch. relocated_virtual_address . to_le_bytes ( ) )
255- . expect ( "failed to write patch to pe file contents" ) ;
254+ cur. write_all ( & patch. relocated_virtual_address . to_le_bytes ( ) ) ?;
256255 applied += 1 ;
257256 }
258257
@@ -279,8 +278,7 @@ impl PEInfo {
279278 }
280279
281280 let relocations =
282- base_relocations:: get_base_relocations ( & self . payload , & self . reloc_section )
283- . expect ( "error parsing base relocations" ) ;
281+ base_relocations:: get_base_relocations ( & self . payload , & self . reloc_section ) ?;
284282 let mut patches = Vec :: with_capacity ( relocations. len ( ) ) ;
285283
286284 for reloc in relocations {
0 commit comments