formats: every mip writes inside the buffers it was given #129
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/129"
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 Zettrox/ztrx. Originally posted by xiaotu030202 on 2026-11-25T13:16:50Z.
What this adds
walkcheckstiled_len >= sizeonce, then computes each row's offset asbase + row(...)and handstiled_row + tiledto the copy closure, which indexes with[..]:Nothing bounds those per row. A mip chain whose tail is placed wrong — the tail is where
first_tail_mipputs the small mips, and wherepadded_dim's rounding differs fromdim's — would index past the buffer and panic rather than answerTooSmall. No test walked a chain at its exact size, so nothing would have caught it.The two tests
every_mip_writes_inside_the_buffers_it_was_given— the seven addressable swizzles, each at four shapes:padded_dim's rounding differs per axisFor each, every mip of every chain is detiled into a tiled buffer of exactly
sizeand a linear buffer of exactly the rows. If any mip's tail offset landed past the chain the indexing would panic here.a_short_tiled_buffer_is_refused_before_any_row_is_read— the checkwalkdoes make: one byte short isTooSmall, not an index. CoversLINEARand a tiled mode.Checked by mutation
Without the check the second test panics where the first would have, so both are load-bearing.
Verification
Windows 11, Rust 1.98.1 (pinned), MSVC 14.44.35207. No game files, no GPU.
What I did not find
No bug here. I went looking for one — the row offsets are computed without a per-row bound, and I expected a tail mip to land past
sizefor some shape. It does not: all 28 mip-and-swizzle combinations are inside. The bounds are right; they were just unheld at the exact size.The
(depth as usize - 1)and(m.height as usize - 1)inneedlooked like an underflow risk too. They are not:dim()ends in.max(1), so every mip is at least 1×1×1.Scope
Same file, same region, and orthogonal to #125's one-line fix — that one is about
addressable()answering wrongly for multisampled linear layouts; this is aboutwalkstaying inside its buffers. Kept separate so either can be reviewed on its own.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.