pe: Add file size check to prevent integer underflow

This commit is contained in:
Mintsuki 2026-01-12 23:46:26 +01:00
parent 81624fce25
commit 94e37b0724
No known key found for this signature in database
GPG Key ID: 1F3C021BECA23821

View File

@ -165,6 +165,10 @@ static void pe64_validate(uint8_t *image, size_t file_size) {
panic(true, "pe: Not a valid PE file");
}
if (file_size < sizeof(IMAGE_NT_HEADERS64)) {
panic(true, "pe: File too small for NT headers");
}
if (dos_hdr->e_lfanew > file_size - sizeof(IMAGE_NT_HEADERS64)) {
panic(true, "pe: e_lfanew offset out of bounds");
}
@ -207,6 +211,10 @@ int pe_bits(uint8_t *image, size_t image_size) {
return -1;
}
if (image_size < sizeof(IMAGE_NT_HEADERS64)) {
return -1;
}
if ((size_t)dos_hdr->e_lfanew > image_size - sizeof(IMAGE_NT_HEADERS64)) {
return -1;
}