Skip to content

Commit 885c0a6

Browse files
committed
fix(object): bounds-check e_ident before reading ELF header
check_elf indexed bytes 4-6 after only verifying the 4-byte magic, panicking on files shorter than 7 bytes.
1 parent 01fc56b commit 885c0a6

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/object/content.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ impl KernelObjectContent {
4444
return false;
4545
}
4646

47+
// Need at least the e_ident fields read below (EI_CLASS, EI_DATA, EI_VERSION).
48+
if self.bytes.len() < 7 {
49+
return false;
50+
}
51+
4752
// Byte 5: EI_CLASS, 0x1 = 32-bit, 0x2 = 64-bit module
4853
if self.bytes[4] != 1 && self.bytes[4] != 2 {
4954
return false;

0 commit comments

Comments
 (0)