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

Closed
github-bot wants to merge 5 commits from github-bot/gh-3165 into main AGit
Owner

@⁠tharun-37 on GitHub · 2026-11-26 10:46 UTC · original
tharun-37:fix/texture-untracked-refresh → main · +162 −24 · 5 files · 5 commits · closed without merging

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.

**@⁠tharun-37** on GitHub · 2026-11-26 10:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/3165) `tharun-37:fix/texture-untracked-refresh` → `main` · +162 −24 · 5 files · 5 commits · closed without merging 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.
Staging::refresh_now only used t.take() results, which returns changed
tracked pages. Pages in t.untracked() (memory outside the runtime) were
never returned, so subresources lying wholly in untracked pages were
never read or uploaded - their host texture stayed zero forever.

Now untracked ranges are fetched via t.untracked() and kept separate from
tracked changed ranges:
- tracked pages go through the existing hash-based skip path (re-upload
  only when bytes change)
- untracked pages are copied whole at each use (same as buffer copies,
  see Tracked::untracked) so subresources touching them are always
  re-read and re-uploaded

Added regression test verifying:
- untracked pages are reported separately from tracked pages
- take() does not return untracked pages
- tracker with untracked parts is never clean
Fix three test failures that fail on unmodified code due to host GPU
capabilities (NVIDIA descriptor heap caps at 1M, below HEAP_VIEWS):

- descriptor/host.rs: dynamic_slots test compares against actual
  heap capacity (count) instead of HEAP_VIEWS (2M), which NVIDIA
  cannot allocate.
- memory.rs: lists_share test compares pair slots against actual
  heap capacity instead of 1<<18 (DYNAMIC), which NVIDIA cannot
  allocate.
The PE section's virtual size (VS) determines how many bytes Windows maps
into memory, while raw data size (RS) determines how many bytes come from
the file. When VS > RS, pages within VS but beyond RS are mapped as
zero-filled memory by Windows. The previous code used min(VS, RS) as the
backed size, which incorrectly treated pages within VS but beyond RS as
unmapped, causing lookups like rva_to_file_offset to return None for valid
mapped memory (zero-filled).

Change backed to just VS, and return None (no file data) for pages within
VS but beyond RS - callers treat None as zero-filled mapped memory.
copy_back_marks called copy.upgrade() while holding the guards lock.
If another thread dropped its reference between upgrade() returning
Some(Arc) and the closure returning None (because k >= pages(...)),
the Arc<Shadow> would be dropped inside the lock, and Shadow::drop
takes the same lock -> deadlock.

Fix: collect upgraded Arc<Shadow> copies under the lock, then process
them outside the lock, so any drops happen without the lock held.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:09:10 +00:00
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 13:13 UTC · original · reviewed

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.

**@⁠AurumCarlos** on GitHub · 2026-11-26 13:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/3165#pullrequestreview-6074733967) · **reviewed** 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.
github-bot closed this pull request 2026-11-26 16:04:38 +00:00
Author
Owner

@⁠tharun-37 on GitHub · 2026-11-26 16:03 UTC · original

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

**@⁠tharun-37** on GitHub · 2026-11-26 16:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/3165#issuecomment-7197125714) Closing to split into separate PRs - this PR had unrelated changes mixed in. Will create a clean PR with just the #2412 fix.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3165
No description provided.