diff --git a/CHANGELOG.md b/CHANGELOG.md index c3ed0ed..7444f96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix ELF firmware parsing error, #77 + ## [0.1.0] - 2024-11-11 ### Added diff --git a/src/firmware.rs b/src/firmware.rs index b831626..e489403 100644 --- a/src/firmware.rs +++ b/src/firmware.rs @@ -196,6 +196,11 @@ pub fn read_elf(elf_data: &[u8]) -> Result { 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."))?;