Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3241: Better handling of stripped ELF section headers (fixes #1119).

Ryan Kurtze6358b593959
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java
index eb3b42114a..3d4e5167e5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfHeader.java
@@ -159,8 +159,14 @@ public class ElfHeader implements StructConverter, Writeable {
e_ehsize = reader.readNextShort();
e_phentsize = reader.readNextShort();
e_phnum = reader.readNextShort();
+ if (e_phnum < 0) {
+ e_phnum = 0; // protect against stripped program headers
+ }
e_shentsize = reader.readNextShort();
e_shnum = reader.readNextShort();
+ if (e_shnum < 0) {
+ e_shnum = 0; // protect against stripped section headers (have seen -1)
+ }
e_shstrndx = reader.readNextShort();
}
catch (IOException e) {