loader: ignore incomplete relocation entries #406

Closed
lordon1a wants to merge 1 commit from upstream-pr/406 into main
lordon1a commented 2026-11-24 02:58:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T02:58:17Z.


AI-assisted.

Problem

In victory_loader::prepare::dir64_relocations, a base relocation block with an odd byte size (block >= 8, e.g. 9) passed block < 8 || at + block > end, causing (at + 8..at + block).step_by(2) to read a 16-bit relocation entry whose second byte lies outside the declared block.

Fix

  • Require block.is_multiple_of(2) alongside block >= 8 and at + block <= end before iterating 16-bit relocation entries.
  • Add unit test prepare::tests::ignores_an_incomplete_relocation_entry verifying that a valid 12-byte block produces the DIR64 entry while a 9-byte block with a trailing incomplete byte is ignored.

Verification

  • cargo xtask policy: 151 files ok
  • cargo test -p victory-loader --lib: 19 passed; 0 failed
  • cargo clippy -p victory-loader --lib --tests -- -D warnings: clean (0 warnings)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6573600658 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/406). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T02:58:17Z. --- AI-assisted. ### Problem In `victory_loader::prepare::dir64_relocations`, a base relocation block with an odd byte size (`block >= 8`, e.g. `9`) passed `block < 8 || at + block > end`, causing `(at + 8..at + block).step_by(2)` to read a 16-bit relocation entry whose second byte lies outside the declared block. ### Fix - Require `block.is_multiple_of(2)` alongside `block >= 8` and `at + block <= end` before iterating 16-bit relocation entries. - Add unit test `prepare::tests::ignores_an_incomplete_relocation_entry` verifying that a valid 12-byte block produces the DIR64 entry while a 9-byte block with a trailing incomplete byte is ignored. ### Verification - `cargo xtask policy`: `151 files ok` - `cargo test -p victory-loader --lib`: `19 passed; 0 failed` - `cargo clippy -p victory-loader --lib --tests -- -D warnings`: clean (0 warnings)
copilot-pull-request-reviewer[bot commented 2026-11-24 06:52:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T02:58:29Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:Marvisak/VIctory:review:6033008932 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/406#pullrequestreview-6033008932). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-24T02:58:29Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
mercuryVM commented 2026-11-24 06:52:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T06:23:21Z.

Review: APPROVED


Tested b33c704 on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (265 passed, 0 failed), including ignores_an_incomplete_relocation_entry.

  • With an odd SizeOfBlock, step_by(2) reached an entry whose second byte lay past the block. Rejecting odd sizes alongside < 8 and the end bound closes that.
  • Like the existing checks, this breaks rather than skipping the block, so a malformed block ends relocation parsing. That matches how the other malformed cases are already handled.
  • The test edits a copy of the test binary's own .reloc and uses no title data.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6034620891 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/406#pullrequestreview-6034620891). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T06:23:21Z. **Review:** APPROVED --- Tested b33c704 on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (265 passed, 0 failed), including `ignores_an_incomplete_relocation_entry`. - With an odd `SizeOfBlock`, `step_by(2)` reached an entry whose second byte lay past the block. Rejecting odd sizes alongside `< 8` and the end bound closes that. - Like the existing checks, this `break`s rather than skipping the block, so a malformed block ends relocation parsing. That matches how the other malformed cases are already handled. - The test edits a copy of the test binary's own `.reloc` and uses no title data. No issues found. AI-assisted (Claude Code).
jeremygold02 commented 2026-11-24 06:55:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:34:48Z.


Thanks @lordon1a for rejecting incomplete DIR64 relocation entries. I tested head b33c704e3335ac2644faafc1ff92bac899e65195 with:

cargo test --locked -p victory-loader --lib ignores_an_incomplete_relocation_entry -- --test-threads=1

Result: 1 passed, 0 failed (18 filtered out). The test checks that a valid 12-byte relocation block retains its DIR64 entry while an odd 9-byte block’s trailing incomplete entry is ignored. This is a synthetic relocation-table parser test, not a title load.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122148390 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/406#issuecomment-7122148390). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:34:48Z. --- Thanks @lordon1a for rejecting incomplete DIR64 relocation entries. I tested head `b33c704e3335ac2644faafc1ff92bac899e65195` with: ``` cargo test --locked -p victory-loader --lib ignores_an_incomplete_relocation_entry -- --test-threads=1 ``` Result: 1 passed, 0 failed (18 filtered out). The test checks that a valid 12-byte relocation block retains its DIR64 entry while an odd 9-byte block’s trailing incomplete entry is ignored. This is a synthetic relocation-table parser test, not a title load.
upstream-sync closed this pull request 2026-11-24 19:02:05 +00:00

Pull request closed

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
Marvisak/VIctory!406
No description provided.