pe: bound data directories to the optional header #396
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/396"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T02:54:56Z.
AI-assisted.
Problem
\ictory_pe::layout::data_directory_offset\ checked \index < NumberOfRvaAndSizes, but did not verify that the requested 8-byte data directory entry actually fits within \IMAGE_FILE_HEADER::SizeOfOptionalHeader\ and the backing file slice. A truncated PE image or inflated \NumberOfRvaAndSizes\ could return an out-of-bounds offset past the optional header or file end.
Fix
Verification
Imported from Marvisak/VIctory. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T02:55:07Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:28:19Z.
Thanks @lordon1a for bounding PE data-directory reads. I tested head
10e9f56a50214df67dca98b19daac0d8e9b04075with:Result: 1 passed, 0 failed (7 filtered out). The synthetic layout regression test checks that directory entries stay within both the optional-header bounds and the file bounds. It covers parser bounds, not loading a real title image.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:40:22Z.
Review: APPROVED
Tested
10e9f56on Windows 11, RTX 5070, MSVC:cargo test -p victory-pe8 passed, includingdirectory_entries_must_fit_in_the_optional_header_and_file.cargo clippy -p victory-pe --all-targetsis clean.SizeOfOptionalHeaderbefore readingNumberOfRvaAndSizes, and checking that the 8-byte entry fits that slice, bounds the offset by both the declared header and the file. An inflated count or a truncated image now returnsNoneinstead of an offset past either.checked_add/checked_mul, and the test covers an index past the count, a one-byte-short file and a one-byte-short header.AI-assisted (Claude Code).
Pull request closed