tooling: pin section probe and paged read bounds in resource_ranges_check #1831

Merged
Asimmimx merged 1 commit from upstream-pr/1838 into main 2026-11-24 19:26:18 +00:00
Asimmimx commented 2026-11-24 19:20:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T19:20:37Z.


Change

tests/resource_ranges_check.py passed against several single-point mutants of
tools/section_probe.py and tools/paged_resource.py. These mutants change
behavior the code states explicitly: the --last tag match, the tag alphabet
that section_tag accepts, the 256 KiB decoded and compressed bounds, the
"window exponent from 8 through 15" method set, the "empty segment" refusal and
the inclusive read budgets. This PR adds cases to the existing check only.

Mutant Existing check With the new cases
SP1 tags[-1] == last dropped survived killed
SP2 tag regex [A-Z0-9_] -> [A-Z_] survived killed
SP3 tag regex [A-Z0-9_] -> [A-Z0-9] survived killed
SP12 tag regex [A-Z0-9_] -> [A-Za-z0-9_] survived killed
SP4 len(decoded) > 256 << 10 -> >= survived killed
SP5 data[first_aligned:-1:16] -> data[first_aligned::16] (IndexError on a final method byte) survived killed
SP7 CMF \x08 removed from the method set survived killed
SP11 compressed input window 256 KiB -> 128 KiB survived killed
SP13 compressed input window 256 KiB -> 512 KiB survived killed
PR1 min(stored, size) <= 0 -> < 0 (empty segments accepted) survived killed
PR2 length > limit dropped survived killed
PR3 length > limit -> >= survived killed
PR4 max(size, stored) > limit -> >= survived killed
PR5 max(size, stored) > limit -> size > limit survived killed
SP8 size < 8 -> size < 9 killed killed
SP9 offset + 8 <= len(data) -> < killed killed
SP10 -base % 16 -> base % 16 killed killed
PR6 segment.offset < physical_end -> <= killed killed
PR7 physical_end > file_size -> >= killed killed
PR8 bisect_right -> bisect_left killed killed
PR10 decoder.unused_data check dropped killed killed
PR11 raw stored != size check dropped killed killed
SP6 FDICT (flags & 0x20) check dropped survived survived (equivalent)
PR9 len(data) != segment.stored check dropped survived survived (equivalent)

The new cases:

  • test_section_windows: a lowercase first tag is rejected; tags A_1Z and
    Z9_0 are accepted; a stream whose last tag is not --last counts as a valid
    zlib stream but not as a layout; an aligned 0x78 as the final byte is skipped
    without an error; a stream with CMF 0x08 (256-byte window, FLG 0x99 so that
    0x0899 is a multiple of 31) is counted.
  • New test_section_window_size_bounds: a table decoding to exactly 256 KiB is
    counted and 256 KiB + 1 is not; a stored (level 0) stream of a 192 KiB table
    (26 bytes overhead) is counted, and one of a 256 KiB table (31 bytes overhead,
    so beyond the 256 KiB input slice) is not.
  • test_ranges: a 3-byte raw read under limit=3 succeeds and under limit=2
    is refused; the 93-byte zlib segment decodes under limit=93; a stored zlib
    segment of 93 + 11 bytes is refused at limit=93 with "exceeds read budget"
    and read at limit=len(stored).
  • test_invalid_segments: Segment(0, 0, 0, "raw"), Segment(0, 1, 0, "zlib")
    and Segment(0, 0, 1, "zlib") are refused by the constructor.

Verification

Based on origin/main 813045b3c1. Windows 11 Pro
26300.9974, Python 3.12.10.

> python -B tests/resource_ranges_check.py
Ran 21 tests in 0.458s
OK
> python -B tests/docs_links_check.py
Self-test passed.
Checked 18 Markdown files and 369 links.
> python -B tests/bidi_controls_check.py
Self-test passed.
Checked 1320 tracked source, script and build/CI files: no bidirectional controls.

Mutants were applied one at a time to the tool by text replacement, the check
was run, and the file was restored. The table above records the exit status of
python -B tests/resource_ranges_check.py for each mutant, before and after
this change.

Evidence and follow-up

  • SP6 is equivalent: without a preset dictionary, zlib.decompressobj() raises
    on an FDICT stream, so the stream is not counted either way. The existing
    dictionary packet in test_section_probe_counts_smaller_zlib_windows already
    covers that result.
  • PR9 is equivalent: a segment's stored length must end exactly at the end of
    the zlib stream (trailing bytes fail the unused_data check), so a short read
    always leaves the stream incomplete and decoder.eof false.
  • Not pinned: the three-window span merging and bytes_sampled in inspect()
    for files above 8 MiB. A fixture for that would need more than 8 MiB of input.
  • All inputs are synthetic and built in the test.

The tool is not changed.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (No capability or build requirement changed.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589572092 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1838). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T19:20:37Z. --- ## Change `tests/resource_ranges_check.py` passed against several single-point mutants of `tools/section_probe.py` and `tools/paged_resource.py`. These mutants change behavior the code states explicitly: the `--last` tag match, the tag alphabet that `section_tag` accepts, the 256 KiB decoded and compressed bounds, the "window exponent from 8 through 15" method set, the "empty segment" refusal and the inclusive read budgets. This PR adds cases to the existing check only. | Mutant | Existing check | With the new cases | |---|---|---| | SP1 `tags[-1] == last` dropped | survived | killed | | SP2 tag regex `[A-Z0-9_]` -> `[A-Z_]` | survived | killed | | SP3 tag regex `[A-Z0-9_]` -> `[A-Z0-9]` | survived | killed | | SP12 tag regex `[A-Z0-9_]` -> `[A-Za-z0-9_]` | survived | killed | | SP4 `len(decoded) > 256 << 10` -> `>=` | survived | killed | | SP5 `data[first_aligned:-1:16]` -> `data[first_aligned::16]` (IndexError on a final method byte) | survived | killed | | SP7 CMF `\x08` removed from the method set | survived | killed | | SP11 compressed input window 256 KiB -> 128 KiB | survived | killed | | SP13 compressed input window 256 KiB -> 512 KiB | survived | killed | | PR1 `min(stored, size) <= 0` -> `< 0` (empty segments accepted) | survived | killed | | PR2 `length > limit` dropped | survived | killed | | PR3 `length > limit` -> `>=` | survived | killed | | PR4 `max(size, stored) > limit` -> `>=` | survived | killed | | PR5 `max(size, stored) > limit` -> `size > limit` | survived | killed | | SP8 `size < 8` -> `size < 9` | killed | killed | | SP9 `offset + 8 <= len(data)` -> `<` | killed | killed | | SP10 `-base % 16` -> `base % 16` | killed | killed | | PR6 `segment.offset < physical_end` -> `<=` | killed | killed | | PR7 `physical_end > file_size` -> `>=` | killed | killed | | PR8 `bisect_right` -> `bisect_left` | killed | killed | | PR10 `decoder.unused_data` check dropped | killed | killed | | PR11 raw `stored != size` check dropped | killed | killed | | SP6 FDICT (`flags & 0x20`) check dropped | survived | survived (equivalent) | | PR9 `len(data) != segment.stored` check dropped | survived | survived (equivalent) | The new cases: - `test_section_windows`: a lowercase first tag is rejected; tags `A_1Z` and `Z9_0` are accepted; a stream whose last tag is not `--last` counts as a valid zlib stream but not as a layout; an aligned `0x78` as the final byte is skipped without an error; a stream with CMF `0x08` (256-byte window, FLG `0x99` so that `0x0899` is a multiple of 31) is counted. - New `test_section_window_size_bounds`: a table decoding to exactly 256 KiB is counted and 256 KiB + 1 is not; a stored (level 0) stream of a 192 KiB table (26 bytes overhead) is counted, and one of a 256 KiB table (31 bytes overhead, so beyond the 256 KiB input slice) is not. - `test_ranges`: a 3-byte raw read under `limit=3` succeeds and under `limit=2` is refused; the 93-byte zlib segment decodes under `limit=93`; a stored zlib segment of 93 + 11 bytes is refused at `limit=93` with "exceeds read budget" and read at `limit=len(stored)`. - `test_invalid_segments`: `Segment(0, 0, 0, "raw")`, `Segment(0, 1, 0, "zlib")` and `Segment(0, 0, 1, "zlib")` are refused by the constructor. ## Verification Based on `origin/main` 813045b3c13f7bad20d8577557b621ee869ccbba. Windows 11 Pro 26300.9974, Python 3.12.10. ```text > python -B tests/resource_ranges_check.py Ran 21 tests in 0.458s OK > python -B tests/docs_links_check.py Self-test passed. Checked 18 Markdown files and 369 links. > python -B tests/bidi_controls_check.py Self-test passed. Checked 1320 tracked source, script and build/CI files: no bidirectional controls. ``` Mutants were applied one at a time to the tool by text replacement, the check was run, and the file was restored. The table above records the exit status of `python -B tests/resource_ranges_check.py` for each mutant, before and after this change. ## Evidence and follow-up - SP6 is equivalent: without a preset dictionary, `zlib.decompressobj()` raises on an FDICT stream, so the stream is not counted either way. The existing dictionary packet in `test_section_probe_counts_smaller_zlib_windows` already covers that result. - PR9 is equivalent: a segment's `stored` length must end exactly at the end of the zlib stream (trailing bytes fail the `unused_data` check), so a short read always leaves the stream incomplete and `decoder.eof` false. - Not pinned: the three-window span merging and `bytes_sampled` in `inspect()` for files above 8 MiB. A fixture for that would need more than 8 MiB of input. - All inputs are synthetic and built in the test. The tool is not changed. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [ ] I updated README/docs when a capability or build requirement changed. (No capability or build requirement changed.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 20:00:55 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1831
No description provided.