loader/prepare: use checked arithmetic and block-bounded reads for ba… #532

Open
pug205gti6 wants to merge 1 commit from upstream-pr/532 into main
pug205gti6 commented 2026-11-25 02:00:45 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by pug205gti6 on 2026-11-25T02:00:45Z.


…se relocations

Fixes unchecked additions and out-of-block reads in victory-loader's PE preparation pass (crates/victory-loader/src/prepare.rs):

  1. dir64_relocations: page + u32::from(e & 0xFFF) panicked in debug builds (and wrapped to a low RVA in release builds) when a relocation page near u32::MAX overflowed; start + size, at + 8, and at + block were also unchecked and end was not clamped to bytes.len().
  2. Odd relocation block sizes: iterating (at + 8..at + block).step_by(2) and slicing bytes.get(entry..entry + 2) read one byte past at + block into the next block's header when block was odd. Iterating bytes[header_end..block_end].as_chunks::<2>().0 keeps all reads strictly within the block.
  3. TLS callback patching and write(): check at + TLS64_ADDRESS_OF_CALLBACKS, tls.directory_rva + TLS64_ADDRESS_OF_CALLBACKS, and at + v.len() with checked_add.
<!-- greyfinch-sync:fxceless/victory-fork:issue:6595414509 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/532). Originally posted by [pug205gti6](https://github.com/pug205gti6) on 2026-11-25T02:00:45Z. --- …se relocations Fixes unchecked additions and out-of-block reads in `victory-loader`'s PE preparation pass (`crates/victory-loader/src/prepare.rs`): 1. `dir64_relocations`: `page + u32::from(e & 0xFFF)` panicked in debug builds (and wrapped to a low RVA in release builds) when a relocation page near `u32::MAX` overflowed; `start + size`, `at + 8`, and `at + block` were also unchecked and `end` was not clamped to `bytes.len()`. 2. Odd relocation block sizes: iterating `(at + 8..at + block).step_by(2)` and slicing `bytes.get(entry..entry + 2)` read one byte past `at + block` into the next block's header when `block` was odd. Iterating `bytes[header_end..block_end].as_chunks::<2>().0` keeps all reads strictly within the block. 3. TLS callback patching and `write()`: check `at + TLS64_ADDRESS_OF_CALLBACKS`, `tls.directory_rva + TLS64_ADDRESS_OF_CALLBACKS`, and `at + v.len()` with `checked_add`.
Revens2 commented 2026-11-25 08:09:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Revens2 on 2026-11-25T07:37:19Z.


Duplicate of #490: @IlyassRS3 opened this patch 31 minutes earlier, and gh pr diff returns the same bytes for both (+118/-23 on 1 file(s), same title).

Please continue in #490 so the review history and any test data stay in one place.
Thanks.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7156066492 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/532#issuecomment-7156066492). Originally posted by [Revens2](https://github.com/Revens2) on 2026-11-25T07:37:19Z. --- Duplicate of #490: @IlyassRS3 opened this patch 31 minutes earlier, and `gh pr diff` returns the same bytes for both (+118/-23 on 1 file(s), same title). Please continue in #490 so the review history and any test data stay in one place. Thanks.
Headache3318 commented 2026-11-25 10:11:11 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Headache3318 on 2026-11-25T09:25:34Z.


Independent verification: PR #532 docs fix Windows GPU driver install instructions merges cleanly, no conflicts. Single file changed crates/victory-loader/src/prepare.rs +118/-23. Build success. Tests fail with pre-existing E0433 errors for Windows-specific modules, unrelated to PR changes. PR builds cleanly and introduces no new errors. Machine: Arch Linux kernel 7.3.5-arch1-1, 3x RTX 4090 driver 620.73.04, Proton, AI-assisted.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7158313007 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/532#issuecomment-7158313007). Originally posted by [Headache3318](https://github.com/Headache3318) on 2026-11-25T09:25:34Z. --- Independent verification: PR #532 docs fix Windows GPU driver install instructions merges cleanly, no conflicts. Single file changed crates/victory-loader/src/prepare.rs +118/-23. Build success. Tests fail with pre-existing E0433 errors for Windows-specific modules, unrelated to PR changes. PR builds cleanly and introduces no new errors. Machine: Arch Linux kernel 7.3.5-arch1-1, 3x RTX 4090 driver 620.73.04, Proton, AI-assisted.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/532:upstream-pr/532'
git switch 'upstream-pr/532'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/532'
git switch 'upstream-pr/532'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/532'
git switch 'upstream-pr/532'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/532'
git switch 'main'
git merge --squash 'upstream-pr/532'
git switch 'main'
git merge --ff-only 'upstream-pr/532'
git switch 'main'
git merge 'upstream-pr/532'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!532
No description provided.