PE: check SizeOfOptionalHeader and slice bounds in data_directory_offset #3024
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3024
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3024"
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?
@fuzeofficlal on GitHub · 2026-11-26 03:41 UTC · original
fuzeofficlal:fix/pe-data-directory-offset-bounds→main· +77 −4 · 1 files · 1 commits · closed without mergingSummary
IMAGE_FILE_HEADER::SizeOfOptionalHeader(FILE_HEADER_SIZE_OF_OPTIONAL_HEADER = 16) and the input slice length incrates/victory-pe/src/layout.rs::data_directory_offset.data_directory_offsettrustedNumberOfRvaAndSizeswithout checking thatNumberOfRvaAndSizesor the full 8-byte data directory entry[off..off + DATA_DIRECTORY_SIZE)lay within the declared optional header (opt + SizeOfOptionalHeader) or withindata.len(), allowing callers such asvictory-loader/src/prepare.rsto receive offsets past the optional header (into the section table) or past EOF.read_u16, update the synthetic PE32+tests::image()fixture to populateSizeOfOptionalHeader, and add two unit tests coveringSizeOfOptionalHeaderboundary enforcement and truncated 8-byte directory entries at slice end.Verification
rustfmt --edition 2024 --check crates/victory-pe/src/layout.rs: ok.cargo test --locked -p victory-pe -p victory-loader: 38victory-peunit tests + 35victory-loaderunit tests + 4 integration tests passed.cargo clippy --locked -p victory-pe -p victory-loader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 191 files ok.@pawrenity on GitHub · 2026-11-26 05:04 UTC · original
VERIFY-3024: verified
a17208fon NVIDIA GeForce RTX 4070, Windows 11 (MSVC toolchain).Tests
cargo test --locked -p victory-pe -p victory-loader: all pass (victory-pe 38 unit tests, victory-loader 35 unit tests plus its integration tests).data_directory_offsetback to its origin/main body and kept the newread_u16/constant/fixture so the tests still compile. Both new tests then fail:data_directory_offset_rejects_entries_past_size_of_optional_header(layout.rs:278) anddata_directory_offset_rejects_truncated_entry_at_end_of_slice(layout.rs:292). The other 10 layout tests still pass.cargo clippy --locked -p victory-pe -p victory-loader --all-targets -- -D warnings: clean.cargo fmt --check -p victory-pe: clean.63bcca4): clean. The PR is based on it.Review against PE/COFF
NumberOfRvaAndSizesas the number of data-directory entries "in the remainder of the optional header", andSizeOfOptionalHeadergives that header's length. So an entry that ends pastopt + SizeOfOptionalHeader, or a count field outside it, is malformed, and rejecting it is correct. The new checks usechecked_addthroughout, and theend <= data.len()bound covers the whole 8-byte entry. No defects found.victory_loader::preparecallsImageInfo::parsefirst. That calls object 0.41'sImageNtHeaders64::parse, which already rejects an image whoseNumberOfRvaAndSizes * 8exceedsSizeOfOptionalHeader - sizeof(IMAGE_OPTIONAL_HEADER64), and one whose optional header runs past EOF. Soprepare()could not actually receive an out-of-header offset before this PR. The fix still matters forlayoutas a standalone public helper.pub fn read_u16has no doc comment. Neither does the existingread_u32.Overlap: an open-PR search for
data_directory_offset,SizeOfOptionalHeaderand "optional header" turned up no competing PR. #2595 (entry points outside the mapped image) is in the same crate area but is a different check.AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-26 06:16 UTC · original
Automated triage for the maintainers.
The new checks in
crates/victory-pe/src/layout.rs::data_directory_offsetare correct as written, but they guard a case that cannot reach this function. Its only production caller isvictory_loader::prepare(crates/victory-loader/src/prepare.rs), which first runsImageInfo::parse(crates/victory-pe/src/image.rs). That goes through object 0.41'sPeFile64::parse, which already rejects an image whoseNumberOfRvaAndSizesentries do not fit insideSizeOfOptionalHeader, or whose optional header runs past the end of the file. The writes inprepareare bounds-checked too (write_u32/writereturn errors). Sopreparecannot receive an offset outside the optional header or past EOF onmain, and no other crate callsdata_directory_offset(only a test inimage.rs).Proposed for closing as a guard for a case that cannot occur. The PR will be closed in 48 hours unless the author pushes a change (for example, showing a caller that reaches
data_directory_offsetwithoutImageInfo::parse) or a maintainer removes the label.CI:
checkpassing.Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-26 06:26 UTC · original
Agreed —
PeFile64::parseinobjectalready validatesSizeOfOptionalHeaderandNumberOfRvaAndSizesbeforevictory_loader::preparecallsdata_directory_offset, and the writes are bounds-checked. Closing to avoid unreachable defensive checks.Pull request closed