mirror of
https://codeberg.org/Limine/Limine
synced 2026-01-26 13:14:28 +00:00
pe: Add file size check to prevent integer underflow
This commit is contained in:
parent
81624fce25
commit
94e37b0724
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user