Bound Bits::any and Bits::all to the representable block limit #458

Closed
github-bot wants to merge 660 commits from github-bot/gh-458 into main AGit
Owner

@⁠ahmetbagci8 on GitHub · 2026-11-29 20:47 UTC · original
ahmetbagci8:fix/gpu-watch-bits-bounds → main · +60034 −5429 · 206 files · 660 commits · closed without merging

Problem

In crates/victory-gpu/src/watch.rs, unlike Bits::set_in which clamps last to Bits::PIECES * Bits::WORDS * 64, neither Bits::any nor Bits::all bounds last:

  1. Near usize::MAX, ((word + 1) * 64).min(last) and (word / Bits::WORDS + 1) * Bits::WORDS * 64 overflow usize (panicking in debug builds and wrapping to
**@⁠ahmetbagci8** on GitHub · 2026-11-29 20:47 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/458) `ahmetbagci8:fix/gpu-watch-bits-bounds` → `main` · +60034 −5429 · 206 files · 660 commits · closed without merging ## Problem In crates/victory-gpu/src/watch.rs, unlike Bits::set_in which clamps last to Bits::PIECES * Bits::WORDS * 64, neither Bits::any nor Bits::all bounds last: 1. Near usize::MAX, ((word + 1) * 64).min(last) and (word / Bits::WORDS + 1) * Bits::WORDS * 64 overflow usize (panicking in debug builds and wrapping to
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 20:51:40 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-11-29 20:52 UTC · original · reviewed

Read against main's Bits. The change is correct:

  • any now clamps last to PIECES * WORDS * 64 (2^31 blocks), as set_in already does. Below that bound the loop is unchanged, and the None branch's jump to the next piece can no longer overflow, since word stays below PIECES * WORDS. A range starting at or past the bound returns false without entering the loop.
  • all returning false for last past the bound matches what it already answered there whenever it got that far: piece() is None beyond the table (self.0.get(..)?), which is the existing !BITS.all(1 << 40, (1 << 40) + 1) case. Only the overflowing arithmetic near usize::MAX is new behaviour.
  • In-range results are unchanged. The existing all assertions in the bits tests still hold, and the new test adds positive in-range cases next to the boundary ones.

For context: a 64 KiB block index of a user-mode address (below 2^47) stays within 2^31, so the runtime's own callers don't reach the clamp. This guards the arithmetic, not a live path. CI is green.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-11-29 20:52 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/458#pullrequestreview-6104748981) · **reviewed** Read against main's `Bits`. The change is correct: - `any` now clamps `last` to `PIECES * WORDS * 64` (2^31 blocks), as `set_in` already does. Below that bound the loop is unchanged, and the `None` branch's jump to the next piece can no longer overflow, since `word` stays below `PIECES * WORDS`. A range starting at or past the bound returns false without entering the loop. - `all` returning false for `last` past the bound matches what it already answered there whenever it got that far: `piece()` is `None` beyond the table (`self.0.get(..)?`), which is the existing `!BITS.all(1 << 40, (1 << 40) + 1)` case. Only the overflowing arithmetic near `usize::MAX` is new behaviour. - In-range results are unchanged. The existing `all` assertions in the bits tests still hold, and the new test adds positive in-range cases next to the boundary ones. For context: a 64 KiB block index of a user-mode address (below 2^47) stays within 2^31, so the runtime's own callers don't reach the clamp. This guards the arithmetic, not a live path. CI is green. AI-assisted: yes
github-bot referenced this pull request from a commit 2026-11-30 15:24:03 +00:00
github-bot closed this pull request 2026-11-30 17:08:28 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-30 17:05 UTC · original

main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

**@⁠TaynanGT** on GitHub · 2026-11-30 17:05 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/458#issuecomment-7285704338) `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.