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

Open
github-bot wants to merge 1 commit from github-bot/gh-532 into main AGit
Owner

@⁠pug205gti6 on GitHub · 2026-11-25 02:00 UTC · original
pug205gti6:pr/490-loader-prepare → main · +118 −23 · 1 files · 1 commits · open

…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.
**@⁠pug205gti6** on GitHub · 2026-11-25 02:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/532) `pug205gti6:pr/490-loader-prepare` → `main` · +118 −23 · 1 files · 1 commits · open …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`.
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`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:45:36 +00:00
Author
Owner

@⁠Revens2 on GitHub · 2026-11-25 07:37 UTC · original

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.

**@⁠Revens2** on GitHub · 2026-11-25 07:37 UTC · [original](https://github.com/fxceless/victory-fork/pull/532#issuecomment-7156066492) 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.
Author
Owner

@⁠Headache3318 on GitHub · 2026-11-25 09:25 UTC · original

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.

**@⁠Headache3318** on GitHub · 2026-11-25 09:25 UTC · [original](https://github.com/fxceless/victory-fork/pull/532#issuecomment-7158313007) 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/532/head:github-bot/gh-532'
git switch 'github-bot/gh-532'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-532'
git switch 'github-bot/gh-532'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-532'
git switch 'github-bot/gh-532'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-532'
git switch 'main'
git merge --squash 'github-bot/gh-532'
git switch 'main'
git merge --ff-only 'github-bot/gh-532'
git switch 'main'
git merge 'github-bot/gh-532'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.