diff --git a/src/elf/section_header.rs b/src/elf/section_header.rs index 981706153..d79d626c7 100644 --- a/src/elf/section_header.rs +++ b/src/elf/section_header.rs @@ -442,13 +442,20 @@ if_alloc! { self.sh_addr as usize..(self.sh_addr as usize).saturating_add(self.sh_size as usize) } /// Parse `count` section headers from `bytes` at `offset`, using the given `ctx` + /// Assuming this is read from the whole file, it will check offset. #[cfg(feature = "endian_fd")] pub fn parse(bytes: &[u8], mut offset: usize, mut count: usize, ctx: Ctx) -> error::Result> { - use scroll::Pread; // Zero offset means no section headers, not even the null section header. if offset == 0 { return Ok(Vec::new()); } + Self::parse_lossy(bytes, offset, count, ctx) + } + /// Parse `count` section headers from `bytes` at `offset`, using the given `ctx` + /// without performing any offset checking to allow parsing relatively + #[cfg(feature = "endian_fd")] + pub fn parse_lossy(bytes: &[u8], mut offset: usize, mut count: usize, ctx: Ctx) -> error::Result> { + use scroll::Pread; let empty_sh = bytes.gread_with::(&mut offset, ctx)?; if count == 0 as usize { // Zero count means either no section headers if offset is also zero (checked