Formats: a depth pitch that overlaps its depth slices is refused #1472
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1472"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T12:58:15Z.
The problem
Layout::walk(crates/victory-formats/src/texture.rs, shared bytileanddetile) computes the linear buffer it needs from the title'srow_pitch/depth_pitch, but it never checks that one depth slice ends before the next one begins. A 3D copy whose depth pitch is smaller than one slice's rows —(height-1)*row_pitch + row bytes— makestile/detileread or write two slices' rows at overlapping addresses and still returnOk, silently losing the earlier slice's rows.This is reachable from the title through xg's texture copy methods (0x40 into / 0x48 out of tiled memory), which pass the title's
row/depthpitches straight intodetile/tile. Silent data corruption, no memory unsafety (the copies stay inside the length they checked).The change
Before copying anything,
walknow computes one slice's extent —(height-1)*row_pitch + row bytes, checked — and requiresdepth_pitch >=it wheneverdepth > 1; a tighter pitch returnsError::TooSmall, exactly as an overlapping row pitch already does (row_pitch < bytes). Two-dimensional copies (depth == 1) are unaffected, as are exact and padded pitches.Evidence
New test
texture::tests::a_depth_pitch_that_overlaps_slices_is_refusedon a4x2x23D layout in LINEAR andSW_4KB_Smodes:Ok(())and the assertion expectsErr(TooSmall)— the test fails on the old code;Verification (base
9a9091d):cargo test -p victory-formats --lib --locked— 28 passed, 0 failed, 4 ignoredcargo test -p victory-hle --lib --locked -- --test-threads=1— 103 passed, 0 failed (xg consumers unchanged)cargo clippy -p victory-formats --all-targets --locked -- -D warningsand--all-features— clean; same forvictory-hlegit diff --checkclean; no new fmt diff (the 12 remainingtexture.rsfmt entries on this toolchain are pre-existing lines, shifted by the added check).Limitation: this rejects the overlapping pitch at validation time; it is a CPU-side contract fix and needs no GPU. A title that relies on the old silent behaviour would now get
E_INVALIDARGfrom xg (the same treatment upstream chose for this class).Coverage note
Open #653 (the upstream-picks bundle) also carries a fix for this defect, but it has been
mergeable=falsesince 2026-11-25. This is an independent implementation written from this mission's audit evidence (the texture audit found the missing overlap check) and copies no code from #653 beyond knowing the problem exists.Imported from fxceless/victory-fork. Originally posted by akimfomin on 2026-11-28T01:24:08Z.
shadPS4 #5453 fixes a separate image geometry boundary by checking legal extent. On
2fe51723the depth-pitch rule could keep two synthetic layout checks tied together: reject a value one byte below a slice's true footprint, accept its exact footprint, and verify a padded six-slice layout still round-trips untouched padding. This compares validation behavior only; the addressing equations are different.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.