loader: avoid u32 overflow and odd-block OOB read in dir64_relocations #46

Merged
ahmetbagci8 merged 1 commit from upstream-pr/46 into dev 2026-11-29 20:55:49 +00:00
ahmetbagci8 commented 2026-11-29 20:44:43 +00:00 (Migrated from github.com)

Imported from edsuuu/VI-BR-PORT. Originally posted by ahmetbagci8 on 2026-11-29T20:44:43Z.


Problem

In crates/victory-loader/src/prepare.rs, dir64_relocations:

  1. Computes page + u32::from(e & 0xFFF) with unchecked u32 addition, which panics in debug builds (or wraps in release builds) on malformed BASERELOC blocks near u32::MAX.
  2. Loops (at + 8..at + block).step_by(2) and reads ytes.get(entry..entry + 2) without ensuring entry + 2 <= at + block, reading 1 byte past the block boundary if lock is odd.

Fix

Loop while entry + 2 <= block_end and use page.checked_add(u32::from(e & 0xFFF)). Added unit test dir64_relocations_skips_overflowing_rva_and_odd_trailing_byte.

Verification

  • cargo test -p victory-loader --lib prepare::tests (5 passed, 0 failed)
  • cargo clippy -p victory-loader --tests (0 warnings)
<!-- greyfinch-sync:edsuuu/VI-BR-PORT:issue:5554929116 --> Imported from [edsuuu/VI-BR-PORT](https://github.com/edsuuu/VI-BR-PORT/pull/46). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-29T20:44:43Z. --- ## Problem In crates/victory-loader/src/prepare.rs, dir64_relocations: 1. Computes page + u32::from(e & 0xFFF) with unchecked u32 addition, which panics in debug builds (or wraps in release builds) on malformed BASERELOC blocks near u32::MAX. 2. Loops (at + 8..at + block).step_by(2) and reads ytes.get(entry..entry + 2) without ensuring entry + 2 <= at + block, reading 1 byte past the block boundary if lock is odd. ## Fix Loop while entry + 2 <= block_end and use page.checked_add(u32::from(e & 0xFFF)). Added unit test dir64_relocations_skips_overflowing_rva_and_odd_trailing_byte. ## Verification - cargo test -p victory-loader --lib prepare::tests (5 passed, 0 failed) - cargo clippy -p victory-loader --tests (0 warnings)
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
edsuuu/VI-BR-PORT!46
No description provided.