Fix #2412: reject out-of-range export addresses in parse_exports #3163

Closed
tharun-37 wants to merge 5 commits from upstream-pr/3165 into main
tharun-37 commented 2026-11-26 10:46:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tharun-37 on 2026-11-26T10:46:45Z.


Fix #2412: Export address validation now uses checked_sub() instead of wrapping_sub(), preventing integer overflow when an export address is below image_base or exceeds u32::MAX.

The previous code used wrapping_sub() which silently wraps/truncates out-of-range addresses into bogus 32-bit RVAs instead of returning an error.

Changes:

  • Addresses below image_base are now rejected with an error
  • Addresses exceeding u32::MAX are now rejected with an error
  • Valid RVAs pass through correctly

Added test rejects_export_address_below_image_base verifying that an export address below image_base is rejected.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6624951511 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3165). Originally posted by [tharun-37](https://github.com/tharun-37) on 2026-11-26T10:46:45Z. --- Fix #2412: Export address validation now uses checked_sub() instead of wrapping_sub(), preventing integer overflow when an export address is below image_base or exceeds u32::MAX. The previous code used wrapping_sub() which silently wraps/truncates out-of-range addresses into bogus 32-bit RVAs instead of returning an error. Changes: - Addresses below image_base are now rejected with an error - Addresses exceeding u32::MAX are now rejected with an error - Valid RVAs pass through correctly Added test rejects_export_address_below_image_base verifying that an export address below image_base is rejected.
AurumCarlos commented 2026-11-26 13:13:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T13:13:38Z.

Review: COMMENTED


Thanks for picking up #2412. The diff carries a lot more than the description says, though: five files, of which only the parse_exports hunk is about export addresses. I'd suggest splitting it, because some of the other changes would be hard to accept as part of this PR.

1. The parse_exports change is fine, but defensive only. object builds ReadTarget::Address as image_base + rva with a 32-bit RVA, so address - image_base is always in 0..=u32::MAX and wrapping_sub was already exact. checked_sub + try_from is a reasonable guard against a future change there. It just can't be reached today, which the description should say rather than describing a live overflow.

2. The new test doesn't test a rejection. rejects_export_address_below_image_base unwraps ImageInfo::parse and expects an alpha export. That only passes because nothing is rejected: the 0x1200 in the address table is an RVA that object adds image_base to, so the address is image_base + 0x1200, not "< image_base" as the comment says. (parse_exports errors propagate through parse with ?, so a real rejection would make the unwrap panic.) As written, it's a test of the valid path under a misleading name.

3. rva_to_file_offset changes behaviour, and it isn't mentioned. On main, backed = vs.min(file_size): raw padding past the virtual size is not part of the section in memory (the comment you removed said so). Now any delta < file_size returns a file offset, so an RVA past a section's virtual end, but inside its raw padding, maps into that padding. With find_map over sections, that can return the wrong bytes for an RVA that belongs to the next section. The new tail, (delta < backed).then_some(None)?, evaluates to None on both branches, so the "mapped as zeros" case is the same as not matching. I'd drop this hunk from the PR.

4. Two GPU tests are weakened.

  • descriptor/host.rs: NumDescriptors >= HEAP_VIEWS (2²¹) becomes >= 4.
  • memory.rs: pairs >= 1 << 18 ("past the dynamic slots") becomes pairs < caps, which checks something different while keeping the old message.

If these fail on your machine because of a capped descriptor heap, that's a real host limitation, and other PRs are handling it on its own (e.g. #3191). Loosening the assertions here would hide regressions on normal hosts.

5. Two GPU fixes deserve their own PRs.

  • shadow.rs / copy_back_marks: the deadlock you describe looks real. In page_of, when k >= pages(..), the upgraded Arc<Shadow> is dropped inside the closure while marks() is held, and Shadow::drop takes marks() again. Collecting the strong refs under the lock and filtering after is the right shape. It's worth a separate PR with its own description and, ideally, a test.
  • texture.rs: re-uploading subresources in untracked pages is a behaviour change to texture refresh, also unrelated to exports. Its test also says "Reserve a 4 KiB window" while WINDOW is 2 * PAGE = 128 KiB, and it never exercises a refresh, only untracked()/take()/clean().

So my suggestion: keep this PR to the parse_exports hunk (with a test that really feeds an out-of-range address, or a note that it's defensive), and send the shadow.rs and texture.rs changes separately. Drop the rva_to_file_offset and test-assertion changes.

<!-- greyfinch-sync:Marvisak/VIctory:review:6074733967 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3165#pullrequestreview-6074733967). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T13:13:38Z. **Review:** COMMENTED --- Thanks for picking up #2412. The diff carries a lot more than the description says, though: five files, of which only the `parse_exports` hunk is about export addresses. I'd suggest splitting it, because some of the other changes would be hard to accept as part of this PR. **1. The `parse_exports` change is fine, but defensive only.** `object` builds `ReadTarget::Address` as `image_base + rva` with a 32-bit RVA, so `address - image_base` is always in `0..=u32::MAX` and `wrapping_sub` was already exact. `checked_sub` + `try_from` is a reasonable guard against a future change there. It just can't be reached today, which the description should say rather than describing a live overflow. **2. The new test doesn't test a rejection.** `rejects_export_address_below_image_base` unwraps `ImageInfo::parse` and expects an `alpha` export. That only passes because nothing is rejected: the `0x1200` in the address table is an RVA that `object` adds `image_base` to, so the address is `image_base + 0x1200`, not "< image_base" as the comment says. (`parse_exports` errors propagate through `parse` with `?`, so a real rejection would make the `unwrap` panic.) As written, it's a test of the valid path under a misleading name. **3. `rva_to_file_offset` changes behaviour, and it isn't mentioned.** On `main`, `backed = vs.min(file_size)`: raw padding past the virtual size is not part of the section in memory (the comment you removed said so). Now any `delta < file_size` returns a file offset, so an RVA past a section's virtual end, but inside its raw padding, maps into that padding. With `find_map` over sections, that can return the wrong bytes for an RVA that belongs to the next section. The new tail, `(delta < backed).then_some(None)?`, evaluates to `None` on both branches, so the "mapped as zeros" case is the same as not matching. I'd drop this hunk from the PR. **4. Two GPU tests are weakened.** - `descriptor/host.rs`: `NumDescriptors >= HEAP_VIEWS` (2²¹) becomes `>= 4`. - `memory.rs`: `pairs >= 1 << 18` ("past the dynamic slots") becomes `pairs < caps`, which checks something different while keeping the old message. If these fail on your machine because of a capped descriptor heap, that's a real host limitation, and other PRs are handling it on its own (e.g. #3191). Loosening the assertions here would hide regressions on normal hosts. **5. Two GPU fixes deserve their own PRs.** - `shadow.rs` / `copy_back_marks`: the deadlock you describe looks real. In `page_of`, when `k >= pages(..)`, the upgraded `Arc<Shadow>` is dropped inside the closure while `marks()` is held, and `Shadow::drop` takes `marks()` again. Collecting the strong refs under the lock and filtering after is the right shape. It's worth a separate PR with its own description and, ideally, a test. - `texture.rs`: re-uploading subresources in untracked pages is a behaviour change to texture refresh, also unrelated to exports. Its test also says "Reserve a 4 KiB window" while `WINDOW` is `2 * PAGE` = 128 KiB, and it never exercises a refresh, only `untracked()`/`take()`/`clean()`. So my suggestion: keep this PR to the `parse_exports` hunk (with a test that really feeds an out-of-range address, or a note that it's defensive), and send the `shadow.rs` and `texture.rs` changes separately. Drop the `rva_to_file_offset` and test-assertion changes.
tharun-37 commented 2026-11-26 16:03:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tharun-37 on 2026-11-26T16:03:39Z.


Closing to split into separate PRs - this PR had unrelated changes mixed in. Will create a clean PR with just the #2412 fix.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197125714 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3165#issuecomment-7197125714). Originally posted by [tharun-37](https://github.com/tharun-37) on 2026-11-26T16:03:39Z. --- Closing to split into separate PRs - this PR had unrelated changes mixed in. Will create a clean PR with just the #2412 fix.
upstream-sync closed this pull request 2026-11-26 16:04:40 +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!3163
No description provided.