tests: cover x2w_inflate blocks, Huffman errors, Adler-32, and zlib framing #3761

Manually merged
github merged 1 commit from github-bot/gh-3759 into gh-pr/3759/base 2026-12-02 02:13:42 +00:00 AGit
Owner

@⁠Ammmae0x on GitHub · 2026-12-01 16:35 UTC · original
Ammmae0x:tests/inflate-unit → main · +1971 −0 · 5 files · 1 commits · merged 2026-12-02 02:07 UTC

Refs #1149.

Standalone portable C++17 unit, boundary, and 1:1 header-mutation tests for x2w_inflate in src/startup_stubs/inflate.h, with zero edits to existing files (5 new files only, +1971/-0; disjoint inflate_unit prefix, tests/startup_inflate_check.py, tests/startup_inflate_probe.cpp, tests/startup_inflate_status.cpp, and CMakeLists.txt untouched).

bits / construct: LSB-first extraction across a byte boundary and the failed flag at EOF; canonical Huffman tables, incomplete sets accepted, over-subscribed sets ({1, 1, 1}, five 2-bit codes) rejected, and decoding symbols 0, 1, 2, 0 from 0x1A.

copy_match / stored / fixed: distance 1 (memset), distance >= 8 with length >= 8 (chunked copy, including the exact length-8 tail), and overlapping periodic copies at distances 3 and 7, through copy_match() directly and through codes() (fast and slow paths); a match at distance 5 after "ABCD" refused with only the literals decoded. Stored blocks: zero length with out == nullptr, a valid payload, bad LEN ^ NLEN, truncated input, and insufficient output (overflow set); reserved block type 3 rejected. Fixed blocks: literals and a match at exact capacity (slow path only) and at 4096 (fast path), plus the fixed tables' counts and decoding 'a' then 'b'.

dynamic / dynamic_rle / dynamic_errors / multi_block: a real dynamic stream (8799 bytes of repeated phrase); a hand-built dynamic block decoding to "ABABA" whose code-length sequence uses the repeat symbols 16, 17 and 18 (the meta check parses the block and pins the code lengths); three hand-built refusals (symbol 16 at index 0, a repeat past nlen + ndist, a missing end-of-block code); and multi-block streams (BFINAL=0 then 1, and a sync flush).

adler32 / zlib framing: "123456789" == 0x091E01DE, empty == 1, and the 5552-byte chunk modulo boundary at 5552, 5553, 11104 and 6000 bytes. inflate_zlib_ex / inflate_zlib: corrupt_stream (null and <6-byte inputs, CM != 8, FCHECK % 31 != 0, FDICT 0x20, HLIT=31, missing/short Adler trailer), insufficient_output (one byte short in each block kind, overflow set, wrapper produced == 0), and bad_checksum (out_size still set to the decoded size, wrapper produced set vs produced == nullptr).

Mutation controls: 7 WILL_FAIL TRUE CMake header-copy controls (fdict_flag, fcheck_mod, stored_nlen, oversubscribed_huffman, dynamic_eob_required, reserved_block_type, adler_modulo) mirrored 1:1 in tests/inflate_unit_meta_check.py, which compiles and runs the real C++ check with g++ (or cl) and every mutant against a real C++ copy, and also parses the dynamic RLE block and cross-checks the embedded streams against CPython's zlib.

Caught in development: the hand-built dynamic RLE block first decoded to "ABBBB" because distance code 0 means distance 1, not 2, so the block now carries two 1-bit distance codes and the match uses code 1; a non-final block still needs its end-of-block code, so the multi-block stream's first block now ends with one; the embedded dynamic stream was first copied with a duplicated row (95 bytes, Adler mismatch), caught by the meta check's zlib cross-check and corrected to the exact 92-byte stream; the fixed-tables decode test first called decode() without consuming the 3 header bits; and a plain drop of the missing-EOB check is unobservable (codes() can never emit symbol 256 without a code for it), so that mutant returns true on a missing EOB instead.

Verification (Linux, this host, g++ -std=c++17):

/tmp/pe-env/bin/python -B tests/inflate_unit_meta_check.py
PASS: inflate_unit: 14 cases, 7/7 mutations killed (g++)

Scratch CMake + CTest (standalone configure of the fragment, via symlinked src/tests under out/inflate-scratch; the full configure needs DXC, unavailable on Linux):

ctest --test-dir out/inflate-scratch/build --no-tests=error -R '^inflate_unit'
100% tests passed, 0 tests failed out of 22

That is 14 per-case tests, inflate_unit_all, and the 7 WILL_FAIL TRUE mutation controls. form_coverage_check.py passes, docs_links_check.py passes (208 files, 802 links), bidi_controls_check.py passes (2827 files), git diff --check is clean, merge-tree exits 0, and the full python-linux suite (tools/run_checks_parallel.py, from the CI workflow) passes with this check included:

all 299 checks passed

No mingw on this host, so no Windows compile check; WIN-VERIFY run is the arbiter.

Windows Verification (119818bc)

  • git merge-tree --write-tree upstream/main HEAD -> 6043debf (exit 0), git diff --check upstream/main...HEAD clean
  • Repo checks: py_compile, form_coverage_check.py, docs_links_check.py (209 files, 806 links), bidi_controls_check.py (2830 files), inflate_unit_meta_check.py (cl: 14 cases, 7/7 mutations killed) passed
  • Commands:
cmake --build --preset dev --target inflate_unit_check inflate_unit_fdict_flag_mut inflate_unit_fcheck_mod_mut inflate_unit_stored_nlen_mut inflate_unit_oversubscribed_huffman_mut inflate_unit_dynamic_eob_required_mut inflate_unit_reserved_block_type_mut inflate_unit_adler_modulo_mut
ctest --preset dev --no-tests=error -j16 -R "^inflate_unit" --output-on-failure
cmake --build --preset release --target inflate_unit_check inflate_unit_fdict_flag_mut inflate_unit_fcheck_mod_mut inflate_unit_stored_nlen_mut inflate_unit_oversubscribed_huffman_mut inflate_unit_dynamic_eob_required_mut inflate_unit_reserved_block_type_mut inflate_unit_adler_modulo_mut
ctest --preset release --no-tests=error -j16 -R "^inflate_unit" --output-on-failure
  • Results: dev 22/22 passed (1.28s); release 22/22 passed (0.99s); direct inflate_unit_check.exe (dev & release): PASS: inflate_unit: 14/14 cases passed. AI-assisted.
**@⁠Ammmae0x** on GitHub · 2026-12-01 16:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3759) `Ammmae0x:tests/inflate-unit` → `main` · +1971 −0 · 5 files · 1 commits · merged 2026-12-02 02:07 UTC Refs #1149. Standalone portable C++17 unit, boundary, and 1:1 header-mutation tests for `x2w_inflate` in `src/startup_stubs/inflate.h`, with zero edits to existing files (5 new files only, +1971/-0; disjoint `inflate_unit` prefix, `tests/startup_inflate_check.py`, `tests/startup_inflate_probe.cpp`, `tests/startup_inflate_status.cpp`, and `CMakeLists.txt` untouched). **`bits` / `construct`**: LSB-first extraction across a byte boundary and the `failed` flag at EOF; canonical Huffman tables, incomplete sets accepted, over-subscribed sets (`{1, 1, 1}`, five 2-bit codes) rejected, and decoding symbols 0, 1, 2, 0 from `0x1A`. **`copy_match` / `stored` / `fixed`**: distance 1 (`memset`), distance >= 8 with length >= 8 (chunked copy, including the exact length-8 tail), and overlapping periodic copies at distances 3 and 7, through `copy_match()` directly and through `codes()` (fast and slow paths); a match at distance 5 after `"ABCD"` refused with only the literals decoded. Stored blocks: zero length with `out == nullptr`, a valid payload, bad `LEN ^ NLEN`, truncated input, and insufficient output (`overflow` set); reserved block type 3 rejected. Fixed blocks: literals and a match at exact capacity (slow path only) and at 4096 (fast path), plus the fixed tables' counts and decoding `'a'` then `'b'`. **`dynamic` / `dynamic_rle` / `dynamic_errors` / `multi_block`**: a real dynamic stream (8799 bytes of repeated phrase); a hand-built dynamic block decoding to `"ABABA"` whose code-length sequence uses the repeat symbols 16, 17 and 18 (the meta check parses the block and pins the code lengths); three hand-built refusals (symbol 16 at index 0, a repeat past `nlen + ndist`, a missing end-of-block code); and multi-block streams (`BFINAL=0` then `1`, and a sync flush). **`adler32` / zlib framing**: `"123456789"` == `0x091E01DE`, empty == 1, and the 5552-byte chunk modulo boundary at 5552, 5553, 11104 and 6000 bytes. `inflate_zlib_ex` / `inflate_zlib`: `corrupt_stream` (null and <6-byte inputs, CM `!= 8`, FCHECK `% 31 != 0`, FDICT `0x20`, `HLIT=31`, missing/short Adler trailer), `insufficient_output` (one byte short in each block kind, `overflow` set, wrapper `produced == 0`), and `bad_checksum` (`out_size` still set to the decoded size, wrapper `produced` set vs `produced == nullptr`). **Mutation controls**: 7 `WILL_FAIL TRUE` CMake header-copy controls (`fdict_flag`, `fcheck_mod`, `stored_nlen`, `oversubscribed_huffman`, `dynamic_eob_required`, `reserved_block_type`, `adler_modulo`) mirrored 1:1 in `tests/inflate_unit_meta_check.py`, which compiles and runs the real C++ check with `g++` (or `cl`) and every mutant against a real C++ copy, and also parses the dynamic RLE block and cross-checks the embedded streams against CPython's zlib. Caught in development: the hand-built dynamic RLE block first decoded to `"ABBBB"` because distance code 0 means distance 1, not 2, so the block now carries two 1-bit distance codes and the match uses code 1; a non-final block still needs its end-of-block code, so the multi-block stream's first block now ends with one; the embedded dynamic stream was first copied with a duplicated row (95 bytes, Adler mismatch), caught by the meta check's zlib cross-check and corrected to the exact 92-byte stream; the fixed-tables decode test first called `decode()` without consuming the 3 header bits; and a plain drop of the missing-EOB check is unobservable (`codes()` can never emit symbol 256 without a code for it), so that mutant returns true on a missing EOB instead. **Verification (Linux, this host, `g++ -std=c++17`)**: ```text /tmp/pe-env/bin/python -B tests/inflate_unit_meta_check.py PASS: inflate_unit: 14 cases, 7/7 mutations killed (g++) ``` Scratch CMake + CTest (standalone configure of the fragment, via symlinked `src`/`tests` under `out/inflate-scratch`; the full configure needs DXC, unavailable on Linux): ```text ctest --test-dir out/inflate-scratch/build --no-tests=error -R '^inflate_unit' 100% tests passed, 0 tests failed out of 22 ``` That is 14 per-case tests, `inflate_unit_all`, and the 7 `WILL_FAIL TRUE` mutation controls. `form_coverage_check.py` passes, `docs_links_check.py` passes (208 files, 802 links), `bidi_controls_check.py` passes (2827 files), `git diff --check` is clean, merge-tree exits 0, and the full `python-linux` suite (`tools/run_checks_parallel.py`, from the CI workflow) passes with this check included: ```text all 299 checks passed ``` No mingw on this host, so no Windows compile check; WIN-VERIFY run is the arbiter. <!-- WIN-VERIFY: passed | sha=119818bc33b416a2d261aee54df52e6de6ab9648 | targets=inflate_unit_check inflate_unit_fdict_flag_mut inflate_unit_fcheck_mod_mut inflate_unit_stored_nlen_mut inflate_unit_oversubscribed_huffman_mut inflate_unit_dynamic_eob_required_mut inflate_unit_reserved_block_type_mut inflate_unit_adler_modulo_mut | ctest=^inflate_unit | release=true --> ### Windows Verification (`119818bc`) - `git merge-tree --write-tree upstream/main HEAD` -> `6043debf` (exit 0), `git diff --check upstream/main...HEAD` clean - Repo checks: `py_compile`, `form_coverage_check.py`, `docs_links_check.py` (209 files, 806 links), `bidi_controls_check.py` (2830 files), `inflate_unit_meta_check.py` (`cl`: `14 cases, 7/7 mutations killed`) passed - Commands: ```text cmake --build --preset dev --target inflate_unit_check inflate_unit_fdict_flag_mut inflate_unit_fcheck_mod_mut inflate_unit_stored_nlen_mut inflate_unit_oversubscribed_huffman_mut inflate_unit_dynamic_eob_required_mut inflate_unit_reserved_block_type_mut inflate_unit_adler_modulo_mut ctest --preset dev --no-tests=error -j16 -R "^inflate_unit" --output-on-failure cmake --build --preset release --target inflate_unit_check inflate_unit_fdict_flag_mut inflate_unit_fcheck_mod_mut inflate_unit_stored_nlen_mut inflate_unit_oversubscribed_huffman_mut inflate_unit_dynamic_eob_required_mut inflate_unit_reserved_block_type_mut inflate_unit_adler_modulo_mut ctest --preset release --no-tests=error -j16 -R "^inflate_unit" --output-on-failure ``` - Results: `dev` 22/22 passed (1.28s); `release` 22/22 passed (0.99s); direct `inflate_unit_check.exe` (`dev` & `release`): `PASS: inflate_unit: 14/14 cases passed`. AI-assisted.
Refs #1149.

Standalone portable C++17 unit, boundary, and 1:1 header-mutation
tests for x2w_inflate in src/startup_stubs/inflate.h, with zero
edits to existing files (5 new files only, disjoint inflate_unit
prefix). bits: LSB-first extraction and the failed flag at EOF.
construct: canonical Huffman tables, incomplete sets accepted,
over-subscribed sets rejected. copy_match: distance 1 memset,
distance >= 8 chunked copy, overlapping periodic copies, and a
match at distance > out_pos refused. stored: zero length with
out == nullptr, valid payload, bad LEN ^ NLEN, truncated input,
insufficient output; reserved type 3 rejected. fixed and dynamic
blocks, slow and fast paths, a hand-built dynamic block using
code-length repeat symbols 16, 17 and 18, dynamic errors, and
multi-block streams. adler32: the 123456789 vector and the
5552-byte chunk modulo boundary. inflate_zlib_ex / inflate_zlib:
corrupt_stream, insufficient_output, and bad_checksum with
out_size set. 7 WILL_FAIL TRUE CMake header-mutation controls
mirrored 1:1 in the meta check.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 16:35:56 +00:00
github-bot changed target branch from main to gh-pr/3759/base 2026-12-02 02:13:34 +00:00
github manually merged commit 119818bc33 into gh-pr/3759/base 2026-12-02 02:13:41 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.