diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:13:36 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:13:36 -0500 |
| commit | 594ceb570d0b5e0ab8fa07c30bb3b8e66ede8b78 (patch) | |
| tree | 38dc04bc0ab49038832308b5d541a1f420bcc0c2 /runtime/src/pe_loader.cpp | |
| parent | 2800fa3bc682c82e579d9cc1dbf5c00d2a484ab7 (diff) | |
| parent | f167f5a82ffcf84e385feac831905cd5c0981a4d (diff) | |
Merge pull request #4329 from Maxime Mansiet
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/pe_loader.cpp')
| -rw-r--r-- | runtime/src/pe_loader.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index d7ea38549..f48ecd940 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp | |||
| @@ -1210,6 +1210,8 @@ Module& Loader::map_image(const std::filesystem::path& path) { | |||
| 1210 | std::memcpy(m->base, file.data(), oh.SizeOfHeaders); | 1210 | std::memcpy(m->base, file.data(), oh.SizeOfHeaders); |
| 1211 | auto* sec = IMAGE_FIRST_SECTION(nt); | 1211 | auto* sec = IMAGE_FIRST_SECTION(nt); |
| 1212 | for (unsigned i = 0; i < nt->FileHeader.NumberOfSections; ++i, ++sec) { | 1212 | for (unsigned i = 0; i < nt->FileHeader.NumberOfSections; ++i, ++sec) { |
| 1213 | if (sec->VirtualAddress < oh.SizeOfHeaders) | ||
| 1214 | throw std::runtime_error(m->name + ": section " + std::to_string(i) + " overlaps the headers"); | ||
| 1213 | uint32_t n = std::min(sec->SizeOfRawData, sec->Misc.VirtualSize ? sec->Misc.VirtualSize : sec->SizeOfRawData); | 1215 | uint32_t n = std::min(sec->SizeOfRawData, sec->Misc.VirtualSize ? sec->Misc.VirtualSize : sec->SizeOfRawData); |
| 1214 | if (!n) continue; | 1216 | if (!n) continue; |
| 1215 | if (sec->PointerToRawData > file.size() || n > file.size() - sec->PointerToRawData) | 1217 | if (sec->PointerToRawData > file.size() || n > file.size() - sec->PointerToRawData) |
| @@ -1235,6 +1237,9 @@ Module& Loader::map_image(const std::filesystem::path& path) { | |||
| 1235 | size_t count = (block->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / 2; | 1237 | size_t count = (block->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / 2; |
| 1236 | for (size_t i = 0; i < count; ++i) { | 1238 | for (size_t i = 0; i < count; ++i) { |
| 1237 | uint16_t type = entries[i] >> 12, off = entries[i] & 0xFFF; | 1239 | uint16_t type = entries[i] >> 12, off = entries[i] & 0xFFF; |
| 1240 | if (type != IMAGE_REL_BASED_ABSOLUTE && | ||
| 1241 | static_cast<uint64_t>(block->VirtualAddress) + off < oh.SizeOfHeaders) | ||
| 1242 | throw std::runtime_error(m->name + ": a relocation lands in the headers"); | ||
| 1238 | if (type == IMAGE_REL_BASED_DIR64) { | 1243 | if (type == IMAGE_REL_BASED_DIR64) { |
| 1239 | require_range(m->name, static_cast<uint64_t>(block->VirtualAddress) + off, sizeof(uint64_t), m->size, | 1244 | require_range(m->name, static_cast<uint64_t>(block->VirtualAddress) + off, sizeof(uint64_t), m->size, |
| 1240 | "a relocation"); | 1245 | "a relocation"); |