diff options
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"); |