diff options
| author | Dominik <55330408+Dom-in@users.noreply.github.com> | 2026-11-22 15:19:53 +0000 |
|---|---|---|
| committer | Dominik <55330408+Dom-in@users.noreply.github.com> | 2026-11-22 15:26:21 +0000 |
| commit | b805f191da65088ca3831fd5f4360e603670aef8 (patch) | |
| tree | 73f3de5103a17c7b8acd439a23cf7ea16403e144 /runtime/src/pe_loader.cpp | |
| parent | 4eb6155d3ac4f9d3fadb0d095c4ce13e76783615 (diff) | |
pe_loader: refuse an export whose address is outside the image
parse_exports range-checks the export directory, its three tables and every
name, but stored each code export as base + rva without checking rva. An
address-table entry at or past SizeOfImage (and outside the export
directory, so not a forwarder) became a pointer past the mapping, which an
import or GetProcAddress through the shims would hand out and a caller would
jump to. The load now fails with the export's name, like every other RVA the
loader follows.
loader_test: an export at SizeOfImage is rejected (it loaded before this
change); one at the image's last byte still loads.
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 | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index 387051756..a291e03d8 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp | |||
| @@ -669,6 +669,8 @@ void Loader::parse_exports(Module& m) { | |||
| 669 | auto add_export = [&](const std::string& key, uint32_t rva) { | 669 | auto add_export = [&](const std::string& key, uint32_t rva) { |
| 670 | if (rva >= dir_begin && rva < dir_end) | 670 | if (rva >= dir_begin && rva < dir_end) |
| 671 | m.forwarders[key] = read_string(m.name, m.base, m.size, rva, "a forwarded export"); | 671 | m.forwarders[key] = read_string(m.name, m.base, m.size, rva, "a forwarded export"); |
| 672 | else if (rva >= m.size) // base + rva would point past the mapping, and a caller would jump there | ||
| 673 | throw std::runtime_error(m.name + ": export " + key + " points outside the image"); | ||
| 672 | else | 674 | else |
| 673 | m.exports[key] = m.base + rva; | 675 | m.exports[key] = m.base + rva; |
| 674 | }; | 676 | }; |