Repository navigation
PE loader: validate full-width named import RVAs before narrowing - #2839
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Built, reviewed, and tested Build & diff checks:
CTest (
Synthetic tests only; no game files. AI-assisted. |
|
Code read of AI-assisted review (Claude Code). |
Kam471
left a comment
There was a problem hiding this comment.
Verified with an MSVC build against current main's files: loader_test -> 71 checks, 0 failed, including the 4 new checks; CTest loader 1/1; test_pe_loader_bounds 50/50. The old loader + new test fails the two (1ull<<32)|0x1120 cases while both valid controls pass. Synthetic PE fixtures only; no game data or absolute paths. Approve.
Non-blocking: the new checks live in loader_test.cpp, not the dedicated test_pe_loader_bounds.cpp.
|
Tested 9ccb105 merged onto main 1628210 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:
AI-assisted (Claude Code). |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claiming: Before this fix,
runtime/src/pe_loader.cpp:1054-1055narrowed a named import thunk's 64-bit AddressOfData to uint32_t before validating its range. A value(1ull << 32) | valid_name_rvatherefore bound the low-RVA name rather than being rejected. The shared binder handles ordinary and delay imports. Read-only checks of coordination issues #2716/#2516 and open upstream PR searches found no matching claim or fix.Claimed in the coordination issue as: new item (claim above; no comment posted to #2716). The item ID can be added by the coordinator.
What and why
Move the existing import-name range check before the uint32_t cast and pass it the full 64-bit AddressOfData value. SizeOfImage is 32-bit, so any non-ordinal value with high bits set now fails before narrowing, using the existing diagnostic:
an import name runs past the image.The shared binder applies the check to both ordinary and eagerly bound delay imports. Ordinal classification and binding remain unchanged.
Add byte-built loader_test cases for ordinary and delay imports, each with a valid control importing testshim.dll!F and a corrupted lookup thunk
(1ull << 32) | 0x1120. The corrupted cases must fail with the import-name range diagnostic; the valid controls must load. All data is synthetic; no game files are used.Overlap checks: searched open upstream PRs for AddressOfData, thunk/RVA, import/truncation, import/32, thunk, import/bounds, and named import. No matching fix found. #2075 concerns mapped module identity/export lookup and #2734 concerns entry-point bounds, not named-import thunk validation. No matching claim found in the bodies/comments of #2716 or #2516.
Tested
Not compiled locally: Linux without MSVC, with cmake/ctest unavailable. The attempted targeted loader CTest run reported
ctest: command not found. Relies on the Windows runtime.yml workflow for compilation and the loader regression test; runtime execution remains unverified locally. No workflow dispatched as part of this change. CPU-only; no GPU or driver involved. AI-assisted (Devin).git diff --checkcompleted without output. Manually reviewed the final diff, byte-built descriptor/table offsets, zero terminators, test shim registration, and the full-width range-check signature.Checklist
docs/design.md(n/a: no translator change).