pe: bound data directory offset by optional header size #3206
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3208"
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 cloph-dsp on 2026-11-26T12:46:59Z.
Depends on: #1633 (claim
PE-DIR-OFFSET; earlier PR #2531 was closed unmerged).data_directory_offsetchecked onlyNumberOfRvaAndSizesand the file length. A malformed header could declare more directories thanSizeOfOptionalHeaderholds, making callers read past the optional header. The function now caps the directory count by the declared optional-header size and refuses entries whose 8 bytes run past that size or the end of the buffer.Test:
layout::tests::data_directory_offset_respects_size_of_optional_headerbuilds a synthetic PE32+ prefix with a two-entry optional header and checks the boundary, an inflated count and a truncated buffer.Validation (Windows, Rust 1.100.0/MSVC, worktree-local
CARGO_TARGET_DIR):cargo test --locked -p victory-pe --lib— 37 passed, 0 failed.git diff --check— clean.origin/main.AI-assisted (Hy4 flash). Synthetic inputs only; no game assets, extracted shaders, logs or DRM material were used or uploaded.
Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T12:57:24Z.
Review: COMMENTED
The bound is right:
NumberOfRvaAndSizesalone shouldn't decide where the table ends, and capping it by(SizeOfOptionalHeader - OPT_DATA_DIRECTORY) / 8matches how the optional header is laid out. A few remarks on the shape of the check:1. The last three checks can't fire. After the first guard,
opt + size <= data.len(). Withcount <= room, we getend = table + count * 8 <= opt + OPT_DATA_DIRECTORY + room * 8 <= opt + size. And sinceindex < count,at + 8 <= end. Soend > opt + size,end > data.len()andat + 8 > data.len()are always false, and the function could end with:That's the original tail, with just the
sizeguard and the cap added above it. It's not wrong as written, but a reader will look for the case each check handles and not find one.2. Because of that, the test's last case is not testing what its comment says.
cutends atopt + OPT_DATA_DIRECTORY + 8, whilesizedeclares two entries, so it's rejected byopt + size > data.len()at the top, not by an entry "that runs past the end of the buffer". The assertion holds, but the comment describes a path that can't be reached. Something like "Nor is a buffer that ends inside the declared optional header" would match.That first guard is also a small behaviour change worth stating: a buffer that ends inside the optional header now yields
Nonefor every index, even entries that are fully present. Onmain, a buffer cut right after entry 0 still returned entry 0. All in-tree callers pass whole files (prepare.rs,image.rs), so nothing breaks, but it's the kind of thing the doc comment ondata_directory_offsetcould mention.3. Verification scope. The description runs
victory-peonly, butvictory-loader/src/prepare.rsalso callsdata_directory_offset(L70, L82, L124, and two tests thatunwrap()it on the test binary). They should pass, since a real linker writes a correctSizeOfOptionalHeader, but acargo test -p victory-loaderrun would confirm it.Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T23:02:24Z.
Windows 11,
63bcca4+ this PR:cargo test -p victory-pe: 37 passed / 0 failed (unpatched63bcca4here: 36).cargo clippy -p victory-pe --all-targets -- -D warnings: clean.data_directory_offset_respects_size_of_optional_headerpasses, and the othervictory-petests are unchanged. Synthetic only. AI-assisted.Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T22:50:32Z.
NVIDIA full-suite run, to go with the reports above by Jackster, since none of them names a GPU run. Tested exact head
8363aaa(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.data_directory_offset_respects_size_of_optional_header.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.