Formats: reject overlapping texture depth slices #351

Manually merged
github merged 1 commit from gh-pr/351/head into gh-pr/351/base 2026-11-26 04:00:13 +00:00
Owner

@⁠pedrofort on GitHub · 2026-11-24 02:30 UTC · original
pedrofort:fix-texture-depth-pitch → main · +86 −3 · 1 files · 1 commits · merged 2026-11-25 00:19 UTC

<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.

**@⁠pedrofort** on GitHub · 2026-11-24 02:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/351) `pedrofort:fix-texture-depth-pitch` → `main` · +86 −3 · 1 files · 1 commits · merged 2026-11-25 00:19 UTC <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>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:00:11 +00:00
github manually merged commit 93a24b7cda into gh-pr/351/base 2026-11-26 04:00:13 +00:00
Author
Owner

@⁠CesarLopesO on GitHub · 2026-11-24 02:48 UTC · original

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!

**@⁠CesarLopesO** on GitHub · 2026-11-24 02:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/351#issuecomment-7120503787) ## 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!
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!351
No description provided.