loader: use checked offsets and sizes in image preparation #670
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!670
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/670/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?
@AdvaitPalve11 on GitHub · 2026-11-24 06:31 UTC · original
AdvaitPalve11:fix/loader-prepare-checked-offsets→main· +63 −17 · 1 files · 2 commits · closed without mergingGuards header, TLS, and base relocation offset calculations against potential integer overflow when processing corrupt or malformed PE images:
@sebastianspicker on GitHub · 2026-11-24 10:48 UTC · original
I ran
victory_loader::prepareunder libFuzzer, seeded with a small synthetic PE32+ (one section, no game bytes). Onmain(ffe310e,prepare.rsunchanged since8e79c80) it panics within a minute atprepare.rs:151withattempt to add with overflow. A base-relocation block whose page RVA is nearu32::MAXmakespage + u32::from(e & 0xFFF)overflow. Debug builds panic; release builds have no overflow checks, so they wrap and compare against the wrong RVA.This PR fixes it. At
44bbd6athe crashing input passes, and 16 million seeded runs in 120 s found nothing else.The two new tests read the test binary as a PE, so they only run on Windows, and neither one hits this case. Here is a test that builds its own image, so it also runs on Linux and macOS. It fails on
mainwith the same overflow and passes on this branch:The fuzz target itself is a few lines in a separate
fuzz/crate outside the workspace. I can put it on a fork branch if that's useful.AI-assisted.
@ErRusso on GitHub · 2026-11-24 11:19 UTC · original
Audit: ✅ Looks good — verified & tested (safety improvement)
Reviewed this PR as part of an audit of mergeable PRs.
crates/victory-loader/src/prepare.rs(+63/-17). Replaces bare+arithmetic in PE image patching withchecked_add()everywhere: file/optional header field offsets, TLS callback offset & RVA, the relocation-table walk bounds, and thewrite()helper.dir64_relocations()additionally guards the per-entry page-offset addition.main.write_rejects_overflowing_offsets→ passed;dir64_relocations_handles_empty_or_truncated_table→ passed on a proper PE (fails on Linux only because it parsescurrent_exe(), which is a non-PE binary here — the same pre-existing limitation affects the other 3 prepare tests on Linux; the Windows CI matrix covers them).usizeoverflow panics (or worse, release-mode wrap). This closes that class of bug.No issues found. Nice defensive hardening.
@catminou4 on GitHub · 2026-11-24 06:38 UTC · original
On
crates/victory-loader/src/prepare.rsline 323 (outdated):ImageInfohas noDefaultimpl — this test target fails to compile everywhere (cargo test -p victory-loader). See review summary for alternatives.@AdvaitPalve11 on GitHub · 2026-11-24 06:45 UTC · original
On
crates/victory-loader/src/prepare.rsline 323 (outdated):Thank you for testing it, Updated the test to parse ImageInfo from the current test binary to match the other tests in prepare.rs. Pushed commit
44bbd6a@Marvisak on GitHub · 2026-11-25 00:27 UTC · original
Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current).
Replaces plain offset arithmetic in image preparation with checked_add chains. The operands come from 32-bit header fields added in 64-bit usize, so none of the usize sums can overflow; the one 32-bit sum only differs for a malformed relocation block and is harmless there. No reachable case, and it triples the size of each header write.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed