loader/prepare: use checked arithmetic and block-bounded reads for base relocations #490
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!490
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-490"
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?
@IlyassRS3 on GitHub · 2026-11-25 01:30 UTC · original
IlyassRS3:fix/loader-prepare-reloc-bounds-and-overflow→main· +118 −23 · 1 files · 1 commits · openSummary
Hardens
victory-loader's PE patching pass (crates/victory-loader/src/prepare.rs) against arithmetic overflow and out-of-block reads on untrusted/malformed relocation tables and header offsets:dir64_relocations):page + u32::from(e & 0xFFF)previously panicked in debug builds (and wrapped in release builds, potentially zeroing an unrelated relocation) when a block hadpagenearu32::MAX. It now useschecked_add.start + size) tobytes.len()withchecked_add, and checksat + 8andat + block.(at + 8..at + block).step_by(2)withbytes.get(entry..entry + 2)previously read 1 byte pastat + blockinto the next block whenblockwas odd. Usingbytes[header_end..block_end].as_chunks::<2>().0keeps reads strictly within each block.write()bounds:checked_addforat + TLS64_ADDRESS_OF_CALLBACKS,tls.directory_rva + TLS64_ADDRESS_OF_CALLBACKS, andwrite()'sat + v.len().Verification
1.98.1, no Windows GPU / no game files.CARGO_FEATURE_PURE=1 cargo clippy --locked -p victory-loader --all-targets --target x86_64-pc-windows-msvc -- -D warningsand--all-features: 0 warnings.cargo test --locked -p xtask: 4 passed, 0 failed (includingrepository_passes_policy).rustc --edition=2024 --test crates/victory-loader/src/prepare.rs(linked against hostvictory-pe,blake3,thiserror): both new tests (dir64_relocations_handle_overflowing_rva_and_odd_blocks,write_rejects_overflowing_offset) passed.upstream/main(a803c87): both new tests panic withattempt to add with overflowon unpatchedprepare.rs(dir64_relocationsline 151 andwriteline 170).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.