Skip to content

Commit

Permalink
fix(firmware): support special ELF program header with p_filesz=0
Browse files Browse the repository at this point in the history
Fix #77
  • Loading branch information
andelf committed Nov 15, 2024
1 parent a2d0386 commit 38c9458
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ pub fn read_elf(elf_data: &[u8]) -> Result<Firmware> {
let binary = object::read::elf::ElfFile::<FileHeader32<Endianness>>::parse(elf_data)?;

let mut sections = vec![];

let endian = elf_header.endian()?;

// Ref: https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-83432/index.html
Expand All @@ -196,6 +195,11 @@ pub fn read_elf(elf_data: &[u8]) -> Result<Firmware> {

let flags = segment.p_flags(endian);

// The number of bytes in the file image of the segment, which can be zero.
if segment.p_filesz(endian) == 0 {
// skip empty segment
continue;
}
let segment_data = segment
.data(endian, elf_data)
.map_err(|_| anyhow::format_err!("Failed to access data for an ELF segment."))?;
Expand Down

0 comments on commit 38c9458

Please sign in to comment.