Fix #2412: reject out-of-range export addresses in parse_exports #3278
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3280"
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 tharun-37 on 2026-11-26T15:39:17Z.
Fix #2412:
parse_exportsnow uses the existingva_to_rvahelper, so export address conversion is checked and shared with TLS callbacks.This is a defensive check:
objectsupplies addresses asimage_base + rvawith a 32-bit RVA, so valid inputs are unaffected. Out-of-range VAs now returnPeError::Malformedinstead of wrapping/truncating.Tests:
keeps_valid_export_rva_when_image_base_is_highcovers the parser path;va_to_rva_rejects_an_address_below_the_image_basepins the checked conversion (below base,u64::MAX, and RVA pastu32).Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T15:41:54Z.
Review: COMMENTED
Thanks for splitting it out, the diff is now just the
parse_exportshunk. A few loose ends:rejects_export_address_below_image_base, but this PR adds no test. Either drop that line, or add a test that really feeds an out-of-range address (the old one passed on the valid path, see my note on #3165).objectgivesimage_base + rvawith a 32-bit RVA, so this can't trigger today. "Preventing integer overflow" would read better as a defensive check.rustfmtallows;cargo fmtshould reflow them.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T16:11:07Z.
Review: APPROVED
Reviewed the diff and verified locally on Windows 11 x64:
address.wrapping_sub(image_base) as u32withchecked_sub(image_base)+u32::try_fromcleanly rejects out-of-range export addresses withPeError::Malformedinstead of silently truncating/wrapping.cargo test -p victory-pe -- --test-threads=1: 36 passed, 0 failed.cargo clippy -p victory-pe --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by tharun-37 on 2026-11-26T17:24:06Z.
Addressed the review notes: replaced the misleading test with
keeps_valid_export_rva_when_image_base_is_high, reworded the description as a defensive check, and verified formatting. CI passes. Left #3165 untouched.Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T01:07:58Z.
Independent Windows verification of PR #3280 (
Fix #2412: reject out-of-range export addresses in parse_exports), headd3242dfd, merge base940d32f.cargo test --locked -p victory-pe --lib -- image::tests::keeps_valid_export_rva_when_image_base_is_high --exact --test-threads=1 --quiet→test result: ok. 1 passed; 0 failed; 36 filtered out, exit 0.git diff --check 940d32f HEAD→ clean, exit 0.origin/mainat940d32f(git grepexit 1). The earlierfinding:referenced old head0a7b5e6; this head adds the named test, so that finding is stale. Only the named synthetic test was run; full crate suite not run here.Windows, Rust 1.100.0/MSVC, worktree-local
CARGO_TARGET_DIR,CARGO_BUILD_JOBS=2. AI-assisted (Hy4 flash). GPU/driver N/A (CPU parser test). No game data, assets, extracted shaders or DRM used.Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-27T01:18:20Z.
On the missing regression test for this guard (FIND-41) — I looked, and it cannot be written against
ImageInfo::parse:PeFile64,MACHINE_AMD64, magic0x20B), andobjectsupplies export addresses asimage_base + rvawith a 32-bit RVA, so on a parsed imagechecked_subcan never fail andtry_fromcan never fail. I checked your headd3242df: an address-table entry of0xFFFF_FFFFparses fine and comes back asrva = Some(0xFFFFFFFF). So a test that goes through the parser would pass with the guard deleted — which is presumably why the one you had was misleading.The file already has the conversion you need, for the TLS callbacks:
va_to_rva(image.rs:442), which does the samechecked_sub+u32::try_fromand is reachable, because a TLS callback VA is read straight from the image. Two small changes:parse_exports, hand the address to it:Verified on Windows 11 with your head as the base:
cargo test -p victory-pe38 passed / 0 failed,cargo clippy -p victory-pe --all-targets -- -D warningsclean. Control: withva_to_rva's body replaced by the oldwrapping_sub(image_base) as u32, the new test fails at its first below-base assertion, so it really does catch the regression.The only visible change is the error text (
VA 0x… is outside the imageinstead ofexport address … outside image_base …); nothing in the tree asserts the old wording, and it makes this file's two conversions one.Synthetic only, no game data. AI-assisted.
Imported from Marvisak/VIctory. Originally posted by tharun-37 on 2026-11-27T02:29:06Z.
Applied @Jackster's suggestion:
parse_exportsnow delegates tova_to_rva, and the helper has a regression test covering below-base,u64::MAX, and RVA pastu32. 38 tests pass; fmt/clippy clean; CI green. Thanks @cloph-dsp for the verification. No other PRs touched.Imported from Marvisak/VIctory. Originally posted by Headache3318 on 2026-11-27T07:17:20Z.
Independent test run of this head, no GPU or game files used.
Environment: Arch Linux x86-64, host
x86_64-unknown-linux-gnu, pinned toolchain fromrust-toolchain.toml(rustc 1.98.1, cargo 1.98.1).Head
021b569a(Use va_to_rva for export addresses):cargo test -p victory-pe --lib -- image::tests::va_to_rva_rejects_an_address_below_the_image_base image::tests::keeps_valid_export_rva_when_image_base_is_high→ 2 passed, 0 failed (0.00 s).cargo test -p victory-pe: 34 passed, 4 failed. The four failures areimage::tests::parses_own_test_binary,rejects_iat_outside_image,rva_to_file_offset_maps_entry_point,rva_to_file_offset_rejects_offsets_past_4_gib— all four fail identically onmainat63bcca4on this host: they parse the test binary itself as a PE, and on a Linux host that binary is ELF. Not caused by this head, and not Windows-behaviour-dependent in a way that should change on Windows hosts.So the two new tests exercise the guard in both directions (valid RVA kept under a high image base; below-base and past-
u32refused) and pass unchanged on a non-Windows host.Also for the record on Marvisak/VIctory#1633
FIND-41: that finding scanned head0a7b5e6and found no regression test. This head addsva_to_rva_rejects_an_address_below_the_image_base(and the high-image-base keep test), and both pass as above — FIND-41 can be closed.No game files, no title data; synthetic fixtures only. AI-assisted (Hermes Agent), runs and verification my own.
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.