bcpack: the destination guard, the dictionary's reach, and the degenerate streams #134
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/134"
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:26:57Z.
Three properties that hold, and nothing held them
decoderefuses a destination that is not whole blocksThe write below uses
chunks_exact_mut, which silently drops a partial trailing block. Without that guard, adstone byte short of a block comes backOk(())with the last byte untouched — a caller reads stale data and gets no error.Checked by mutation:
That string is the guard's whole justification.
The test walks all six BC numbers at 0, 1, 2 and 5 blocks, each one byte short and one byte long, and asserts the message. It also pins the other two refusals: an empty destination, and a BC number outside 1/3–7.
pickindexes the dictionary with a byte, and the size is exactrcomes fromreferences, which returnsusize::from(u8)— so at most 255. At block 0 the deepest reachable index is255 - 1 = 254.DICTIONARYis255, which is exactly enough and no more.There is no
.get(), no clamp: the bound is arithmetic, not defensive. Shrinking the constant by one panics on the first block that reaches back that far, and nothing said so.The degenerate streams
noise_never_panicswalks pseudo-random streams of many lengths. The shapes a real chunk actually starts from — all zeros, all ones,0xAA,0x55— were not among them.the_degenerate_streams_never_panicruns four fills × nine lengths × six BC numbers × two block counts. It asserts only "no panic", which is all a decoder can promise for input it was not given a size for.Verification
Windows 11, Rust 1.98.1 (pinned), MSVC 14.44.35207. No game files, no GPU.
No bug found
All three properties hold on the code as written. I went looking for an out-of-bounds in
pickand a silent short write indecode; the first is guarded byDICTIONARY == 255matching the byte range exactly, the second by the guard now under test. Both are on record so a change to either side has to notice the other.One thing worth flagging for whoever owns this file: the
pickbound is arithmetically exact rather than defensive. If the reference encoding ever widens past a byte, that is a panic rather than an error — andthe_dictionary_covers_every_reference_a_record_can_nameis what would say so first.Where this sits among my other PRs on this crate
texture.rstexture.rsaddressable()wrong for multisampled linear layouts (a bug)texture.rswalkstaying inside its bufferstexture.rsbcpack.rsFive PRs in one crate is a lot; happy to squash them into two (the
texture.rsbugfix, and the tests) if that is easier to review.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.