PE: bound data_directory_offset by SizeOfOptionalHeader and buffer length #2531
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!2531
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2531/head"
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?
@reeledMarek on GitHub · 2026-11-25 15:23 UTC · original
reeledMarek:fix/pe-data-directory-bounds→main· +44 −3 · 1 files · 1 commits · closed without mergingProblem
victory_pe::layout::data_directory_offsetchecked onlyindex < NumberOfRvaAndSizeswithout checkingIMAGE_FILE_HEADER::SizeOfOptionalHeaderor the input buffer length.For a PE32+ image with a short
SizeOfOptionalHeader(e.g. 128 bytes / 2 directories) andNumberOfRvaAndSizes = 16,ImageInfo::parse(viaobject) clamps directories toSizeOfOptionalHeaderand accepts the image, whiledata_directory_offsetreturned offsets past the optional header directly into the section header table (whichvictory-loader::preparethen patches). Similarly, truncated buffers pastNumberOfRvaAndSizesreturned out-of-bounds offsets.Fix
FILE_HEADER_SIZE_OF_OPTIONAL_HEADERandread_u16.NumberOfRvaAndSizesto 16, verify the directory entry ends withinSizeOfOptionalHeader, and verifyoffset + DATA_DIRECTORY_SIZE <= data.len().Testing
data_directory_offset_respects_size_of_optional_headerand truncated-buffer check incrates/victory-pe/src/layout.rs.cargo test -p victory-pe --locked layoutand Windows cross-clippy (-D warnings).@Marvisak on GitHub · 2026-11-25 15:52 UTC · original
Automated triage for the maintainers.
Recommended for a look.
layout::data_directory_offset(crates/victory-pe/src/layout.rs) now also bounds the entry bySizeOfOptionalHeader, clampsNumberOfRvaAndSizesto 16 and checks the buffer length, sovictory-loader'spreparecan no longer patch bytes past the optional header (e.g. in the section table) on a malformed image. I checked the callers in prepare.rs and image.rs (they use real linker output, which setsSizeOfOptionalHeadercorrectly) and the updated test fixture. CI (clippy + tests on Windows): passing.Generated by Claude Code
@Marvisak on GitHub · 2026-11-25 22:10 UTC · original
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because the premise does not hold.
object0.41.0'sDataDirectories::parsereadsNumberOfRvaAndSizesentries from theSizeOfOptionalHeader-sized slice and fails if they do not fit: a PE32+ with a 128-byte optional header and 16 directories givesMalformed("Invalid PE number of RVA and sizes")fromImageInfo::parse. The only production caller parses the same bytes with it first, so neither case can reachdata_directory_offset.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed