m4b / goblin

An impish, cross-platform binary parsing crate, written in Rust
MIT License
1.17k stars 156 forks source link

elf.reloc: add workaround for 0-sized relas #339

Closed Jhynjhiruu closed 1 year ago

Jhynjhiruu commented 1 year ago

Some ELF files include a .rela section with size 0 instead of simply not including the section. This caused issues with the parser, since bytes.pread_with(offset, filesz) would try and read 0 bytes from a 0-length buffer, which returned an error. This workaround simply swaps out the value with the entire input when filesz is 0; this is the smallest change that appears to work, since count will then be set to 0. This could also be worked around by adding a check in elf.mod (or many other methods), but I thought that it was better to allow the parser to handle 0-sized sections.