This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed
rustc_codegen_ssa/src/back Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -305,8 +305,13 @@ pub fn create_compressed_metadata_file(
305305 symbol_name : & str ,
306306) -> Vec < u8 > {
307307 let mut compressed = rustc_metadata:: METADATA_HEADER . to_vec ( ) ;
308- compressed. write_all ( & ( metadata. raw_data ( ) . len ( ) as u32 ) . to_be_bytes ( ) ) . unwrap ( ) ;
308+ // Our length will be backfilled once we're done writing
309+ compressed. write_all ( & [ 0 ; 4 ] ) . unwrap ( ) ;
309310 FrameEncoder :: new ( & mut compressed) . write_all ( metadata. raw_data ( ) ) . unwrap ( ) ;
311+ let meta_len = rustc_metadata:: METADATA_HEADER . len ( ) ;
312+ let data_len = ( compressed. len ( ) - meta_len - 4 ) as u32 ;
313+ compressed[ meta_len..meta_len + 4 ] . copy_from_slice ( & data_len. to_be_bytes ( ) ) ;
314+
310315 let Some ( mut file) = create_object_file ( sess) else {
311316 return compressed. to_vec ( ) ;
312317 } ;
Original file line number Diff line number Diff line change @@ -799,14 +799,14 @@ fn get_metadata_section<'p>(
799799 }
800800
801801 // Length of the compressed stream - this allows linkers to pad the section if they want
802- let usize_len = core:: mem:: size_of :: < u32 > ( ) ;
803- let Ok ( len_bytes) = <[ u8 ; 4 ] >:: try_from ( & buf[ header_len..cmp:: min ( header_len + usize_len , buf. len ( ) ) ] ) else {
802+ let u32_len = core:: mem:: size_of :: < u32 > ( ) ;
803+ let Ok ( len_bytes) = <[ u8 ; 4 ] >:: try_from ( & buf[ header_len..cmp:: min ( header_len + u32_len , buf. len ( ) ) ] ) else {
804804 return Err ( MetadataError :: LoadFailure ( "invalid metadata length found" . to_string ( ) ) ) ;
805805 } ;
806806 let compressed_len = u32:: from_be_bytes ( len_bytes) as usize ;
807807
808808 // Header is okay -> inflate the actual metadata
809- let compressed_bytes = & buf[ header_len.. compressed_len + header_len] ;
809+ let compressed_bytes = & buf[ ( header_len + u32_len ) .. ( compressed_len + header_len + u32_len ) ] ;
810810 debug ! ( "inflating {} bytes of compressed metadata" , compressed_bytes. len( ) ) ;
811811 // Assume the decompressed data will be at least the size of the compressed data, so we
812812 // don't have to grow the buffer as much.
You can’t perform that action at this time.
0 commit comments