Skip to content

Commit

Permalink
Fix bug in copy_section_data
Browse files Browse the repository at this point in the history
The compressed data begins after the compression header.
  • Loading branch information
marxin authored and davidlattimore committed Aug 29, 2024
1 parent af76c8f commit 7e98c91
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions wild_lib/src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ impl<'data> File<'data> {

let decompressed = CompressedData {
format,
data: &data
[core::mem::size_of::<object::elf::CompressionHeader64<LittleEndian>>()..],
data: &data[COMPRESSION_HEADER_SIZE..],
uncompressed_size: compression.ch_size.get(LittleEndian),
}
.decompress()?;
Expand All @@ -161,6 +160,7 @@ impl<'data> File<'data> {
let data = section.data(LittleEndian, self.data)?;

if let Some((compression, _, _)) = section.compression(LittleEndian, self.data)? {
let data = &data[COMPRESSION_HEADER_SIZE..];
match compression.ch_type.get(LittleEndian) {
object::elf::ELFCOMPRESS_ZLIB => {
flate2::Decompress::new(true).decompress(
Expand Down Expand Up @@ -332,6 +332,8 @@ pub(crate) const PHEADER_OFFSET: u64 = FILE_HEADER_SIZE as u64;
pub(crate) const FILE_HEADER_SIZE: u16 = 0x40;
pub(crate) const PROGRAM_HEADER_SIZE: u16 = 0x38;
pub(crate) const SECTION_HEADER_SIZE: u16 = 0x40;
pub(crate) const COMPRESSION_HEADER_SIZE: usize =
core::mem::size_of::<object::elf::CompressionHeader64<LittleEndian>>();

pub(crate) const GOT_ENTRY_SIZE: u64 = 0x8;
pub(crate) const PLT_ENTRY_SIZE: u64 = PLT_ENTRY_TEMPLATE.len() as u64;
Expand Down

0 comments on commit 7e98c91

Please sign in to comment.