runtime: check the DirectStorage stand-in's zlib decoder against zlib #1397
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1404"
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 R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T10:41:48Z.
Change
Adds a direct check for the DirectStorage stand-in's zlib decoder,
src/startup_stubs/inflate.h, as one more startup-stand-in slice of #1149. The stand-in inflates zlib requests with this decoder. Before this change, the stub-consumer fixtures only reached stored blocks, a fixed block that repeats one byte at distance 1, and single-byte runs.tests/startup_inflate_probe.cpprunsx2w_inflate::inflate_zlibon a zlib stream, orx2w_inflate::inflate_rawon bare deflate data (rawmode), into a destination followed by 16 guard bytes (0xA5). It reportsinflated <size>,rejected(in raw mode with the number of bytes decoded before the rejection), or a write past the capacity.tests/startup_inflate_check.py(cteststartup_inflate) has CPython'szlibencode seeded synthetic data, and each decoded result must equal the input:Z_FIXED) and a dynamic block over random literals and copies of 3–258 bytes from 1–32 000 bytes back;ABCD, a length-3 match at distance 4 decodes toABCDABC. The same block with distance 5 is rejected with only the four literals decoded, before the match copies anything. CPython's zlib also rejects it (wbits=-15).The decoder is not changed. The test is registered with the other Python-driven startup tests. It is not added to the
prpreset, so the fullmainand manual workflows run it with the rest of the suite. It runs in under a second without a GPU or game files, so it can move into the preset if you prefer.docs/startup-runtime.mdhas the command.Refs #1149
Verification
On
a953c41a(based ona8946ec0), Windows 11, MSVC 14.51, Python 3.14.5 (zlib-ng 1.3.1),devpreset:Negative control: I broke
inflate.hone way at a time, rebuilt the probe and reran the check. Each mutation fails it:fixed: exit 1: rejectedfixed: exit 1: rejectedfixed: exit 1: rejecteddistance > out_pos + 1)raw_distance_5: exit 0: inflated 7distance >= out_pos)raw_distance_4: exit 1: rejected after 4 bytesraw_distance_5: exit 0: inflated 7dynamic_short_capacity: exit 3: wrote past the destination at +0dynamic_sparse: exit 1: rejecteddynamic_sparse: exit 1: rejecteddynamic: exit 1: rejectedstored: exit 1: rejectedOn the first revision, with the last-distance-code and no-distance-bound mutations applied together,
startup_stubsandstartup_storage_directory_batchstill passed and onlystartup_inflatefailed. Ona953c41a, with the header unchanged, all three pass.tests/docs_links_check.py,tests/bidi_controls_check.pyandgit diff --checkpass.Evidence and follow-up
All inputs are generated at test time from a fixed seed with CPython's
zlib. The distance-bound blocks are hand-built from RFC 1951's fixed code table. No external data is involved. The check compares only decoded bytes and the first block's type, not compressed bytes, so it should not depend on the zlib build. I ran it locally only with zlib-ng 1.3.1.Not covered here: header rejection (
FDICT, method,FCHECK), reserved block type 3 and storedLEN/NLENmismatches. The stub consumer already covers a damaged Adler-32.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T10:51:35Z.
Review: CHANGES_REQUESTED
The zlib comparison adds useful coverage for valid long back-references, dynamic Huffman blocks, truncation and output capacity. Please keep those cases and check invalid-distance rejection at the bounds-validation step. The crafted guard-byte case is designed to make an unchecked read observable if the guard is removed. A focused check of the distance validation can protect that rule without adding an out-of-bounds-read demonstration to the fixture.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:52:53Z.
Review: COMMENTED
Reviewed commit
c4fb0f7fd5c550263288cb92dbaaba85ef5ee5e5:tests/startup_inflate_probe.cpp(16-byte0xA5before/after destination guards checked regardless of decode outcome) andtests/startup_inflate_check.py(checkssrc/startup_stubs/inflate.hagainst CPython'szlibacross 8 cases—stored, fixed, dynamic, spare capacity, sparse alphabet with repeat codes 16/17/18, sync flush across an empty stored block, empty stream, and distance-1 match—plus 3 negative controls: 1-byte short capacity, truncated stream, and distance-2 match before output start with matching guard-byte checksum), wired intoCMakeLists.txt(startup_inflate) anddocs/startup-runtime.md.git diff --checkclean;tests/docs_links_check.py(16 Markdown files, 319 links) andtests/bidi_controls_check.py(1182 files) passed.--preset dev,startup_inflate_probe): 1/1 passed (startup_inflate)./O2(--preset release,startup_inflate_probe): 1/1 passed (startup_inflate).Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T11:01:47Z.
Thanks.
a953c41aremoves the guard-byte case and checks the distance bound directly:rawmode that runsinflate_rawon bare deflate data, so neither the zlib header nor the Adler-32 check can reject the stream. The guard before the destination is gone. The guard after it remains for the capacity control.ABCD, a length-3 match at distance 4 decodes toABCDABC. The same block with distance 5 is rejected with only the four literals decoded (rejected after 4 bytes), so the rejection comes from the bound before the copy.ctest --preset dev --no-tests=error -R '^startup_inflate$' -Vpasses ona953c41a(8 cases decoded, 3 controls rejected). Relaxing the bound todistance > out_pos + 1failsraw_distance_5(inflated 7). Tightening it todistance >= out_posfailsraw_distance_4(rejected after 4 bytes). The PR description has the updated output and mutation table.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T11:16:41Z.
Review: APPROVED
Re-reviewed
a953c41. Windows Release startup_inflate passed with eight comparisons and three rejection controls. The revised test checks invalid input rejection using the intact decoder.