Formats: reject overlapping texture depth slices #351

Merged
pedrofort merged 1 commit from upstream-pr/351 into main 2026-11-25 00:19:36 +00:00
pedrofort commented 2026-11-24 02:30:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pedrofort on 2026-11-24T02:30:45Z.


<head></head>

Problem

Layout::walk() validates row pitch and total buffer size but does not ensure that the depth pitch separates individual slices of a 3D texture.

Both tile() and detile() can therefore accept overlapping linear depth slices without reporting an error.

Fix

  • Calculate the minimum occupied byte span of a depth slice using checked arithmetic.

  • Reject insufficient depth pitches when copying multiple slices.

  • Preserve valid tightly packed and padded layouts.

  • Preserve the existing overflow checks.

Verification

Apple M5, macOS arm64, Rust 1.98.1, base commit d2a4bae.

Test | Before | After -- | -- | -- Overlapping detile slices | FAIL | PASS Overlapping tile slices | FAIL | PASS Exact and padded slice pitches | PASS | PASS Full formats suite | — | 23 passed, 0 failed, 3 ignored

Tests cover both linear and 4 KiB standard tiled layouts and verify that rejected copies leave destination buffers unchanged.

Clippy: clean.

Asset policy: 151 files OK.

All tests use synthetic data. No game assets were used.

AI-assisted implementation and test preparation (ChatGPT), with results verified locally on Apple Silicon.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573278823 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/351). Originally posted by [pedrofort](https://github.com/pedrofort) on 2026-11-24T02:30:45Z. --- <head></head><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Problem</span></h2><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><code><span>Layout::walk()</span></code><span><span class="Apple-converted-space"> </span>validates row pitch and total buffer size but does not ensure that the depth pitch separates individual slices of a 3D texture.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Both<span class="Apple-converted-space"> </span></span><code><span>tile()</span></code><span><span class="Apple-converted-space"> </span>and<span class="Apple-converted-space"> </span></span><code><span>detile()</span></code><span><span class="Apple-converted-space"> </span>can therefore accept overlapping linear depth slices without reporting an error.</span></p><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Fix</span></h2><ul style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><li><p><span>Calculate the minimum occupied byte span of a depth slice using checked arithmetic.</span></p></li><li><p><span>Reject insufficient depth pitches when copying multiple slices.</span></p></li><li><p><span>Preserve valid tightly packed and padded layouts.</span></p></li><li><p><span>Preserve the existing overflow checks.</span></p></li></ul><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Verification</span></h2><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Apple M5, macOS arm64, Rust 1.98.1, base commit<span class="Apple-converted-space"> </span></span><code><span>d2a4bae</span></code><span>.</span></p> Test | Before | After -- | -- | -- Overlapping detile slices | FAIL | PASS Overlapping tile slices | FAIL | PASS Exact and padded slice pitches | PASS | PASS Full formats suite | — | 23 passed, 0 failed, 3 ignored <p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Tests cover both linear and 4 KiB standard tiled layouts and verify that rejected copies leave destination buffers unchanged.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Clippy: clean.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Asset policy: 151 files OK.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>All tests use synthetic data. No game assets were used.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>AI-assisted implementation and test preparation (ChatGPT), with results verified locally on Apple Silicon.</span></p>
CesarLopesO commented 2026-11-24 06:55:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by CesarLopesO on 2026-11-24T02:48:54Z.


Independent validation — Debian 13 (Trixie)

I tested the current PR head 93a24b7 locally on Debian 13.

Results

  • cargo test --locked -p victory-formats --lib texture::tests::depth_pitch_ — 3 passed, 0 failed.
  • cargo test --locked -p victory-formats — 23 passed, 0 failed, 3 ignored.
  • cargo clippy --locked -p victory-formats --all-targets -- -D warnings — passed with no warnings.
  • cargo xtask policy — passed (151 files).
  • git diff --check — passed; working tree clean.

The focused tests cover overlapping depth pitches in both tile() and detile(), plus exact and padded slice pitches. The full victory-formats suite also passes on Linux.

I did not run the full workspace test suite as part of this validation.

No game files or game data were used.

Thanks for the fix!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7120503787 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/351#issuecomment-7120503787). Originally posted by [CesarLopesO](https://github.com/CesarLopesO) on 2026-11-24T02:48:54Z. --- ## Independent validation — Debian 13 (Trixie) I tested the current PR head `93a24b7` locally on Debian 13. **Results** - `cargo test --locked -p victory-formats --lib texture::tests::depth_pitch_` — 3 passed, 0 failed. - `cargo test --locked -p victory-formats` — 23 passed, 0 failed, 3 ignored. - `cargo clippy --locked -p victory-formats --all-targets -- -D warnings` — passed with no warnings. - `cargo xtask policy` — passed (151 files). - `git diff --check` — passed; working tree clean. The focused tests cover overlapping depth pitches in both `tile()` and `detile()`, plus exact and padded slice pitches. The full `victory-formats` suite also passes on Linux. I did not run the full workspace test suite as part of this validation. No game files or game data were used. Thanks for the fix!
mercuryVM commented 2026-11-24 11:03:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:05:32Z.

Review: APPROVED


Tested 93a24b7 on Windows 11, RTX 5070, MSVC: the workspace passes (198 outside victory-shader), including the three new depth_pitch_* tests on both linear and SW_4KB_S.

The check is exact. A slice occupies (height − 1) · row_pitch + width · bytes, so with more than one slice, any depth_pitch smaller than that makes consecutive slices overlap. Rejecting it with TooSmall before any copy, which the tests show leaves the destination untouched, closes the gap. Single-slice copies (any pitch, including 0) and D3D12-style footprints (pitch = rows · row_pitch) are unaffected.

No issues found. Nit: the description is pasted rich HTML. Plain Markdown would read better on GitHub.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6037224537 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/351#pullrequestreview-6037224537). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T10:05:32Z. **Review:** APPROVED --- Tested 93a24b7 on Windows 11, RTX 5070, MSVC: the workspace passes (198 outside `victory-shader`), including the three new `depth_pitch_*` tests on both linear and `SW_4KB_S`. The check is exact. A slice occupies `(height − 1) · row_pitch + width · bytes`, so with more than one slice, any `depth_pitch` smaller than that makes consecutive slices overlap. Rejecting it with `TooSmall` before any copy, which the tests show leaves the destination untouched, closes the gap. Single-slice copies (any pitch, including 0) and D3D12-style footprints (pitch = rows · row_pitch) are unaffected. No issues found. Nit: the description is pasted rich HTML. Plain Markdown would read better on GitHub. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 01:03:28 +00:00
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!351
No description provided.