tooling: pin stream limits, 29-bit ids and empty tags in awc_metadata_check #1830

Merged
Asimmimx merged 1 commit from upstream-pr/1837 into main 2026-11-24 19:36:00 +00:00
Asimmimx commented 2026-11-24 19:20:28 +00:00 (Migrated from github.com)

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


Change

tests/awc_metadata_check.py exercised the AWC reader's rejections well, but several documented acceptance boundaries in tools/awc_metadata.py had no case. A single-point change to each of them left the check green:

  • the 4,096-stream limit for sound-effect banks (only 4,097 was rejected);
  • the lower bound of the stream count (a count of 0 reaches entries[0] and raises IndexError instead of the specific ValueError);
  • the 29-bit stream ID: entry & 0x1fffffff decides between a sound-effect bank and a streamed music bank, and detects a second ID-0 stream in a music bank. ID 0x10000000 sets only bit 28;
  • "one nonempty data tag" for a sound-effect stream (only the music path had an empty-data-tag case);
  • the exclusion of empty tags from the overlap check (if length:), in both paths;
  • half-open extents in the sound-effect path: a data tag that ends where the format tag begins is not an overlap (the music path already had this case).

I applied 14 single-point mutants by hand to tools/awc_metadata.py, ran the check after each and reverted:

Mutant Existing check With the new cases
M1 1 <= count <= 4096 -> < 4096 survived killed (4096 streams)
M2 1 <= count -> 0 <= count survived killed (empty stream table)
M3 read_bank: entries[0] & 0x1fffffff -> 0x0fffffff survived killed (sfx stream id 0x10000000)
M4 read_formats: entries[0] & 0x1fffffff == 0 -> 0x0fffffff survived killed (sfx stream id 0x10000000)
M5 sfx: kind == 0x55 and length -> kind == 0x55 survived killed (empty data tag)
M6 sfx: if length: before spans.append -> always survived killed (empty tag inside the format tag)
M7 sfx overlap left[1] > right[0] -> >= survived killed (data touching the format tag, 4096 streams)
M8 music duplicate-ID mask 0x1fffffff -> 0x0fffffff survived killed (music stream id 0x10000000)
M9 music: if length: before spans.append -> always survived killed (empty tag inside the music header)
M10 table <= header_size -> table < header_size survived survived (see below)
M11 music overlap > -> >= killed killed
M12 sfx extent check reduced to header_size <= start killed killed
M13 sfx samples += -> samples = killed killed
M14 flag word 0xff020001 dropped killed killed

The new cases:

  • test_rejects_invalid_metadata gains two patches of the existing fixture: a stream count of 0, and the first sound's data tag set to length 0 (that sound keeps its 0x76 tag, so it has no nonempty data tag).
  • New test_sfx_accepts_limits reads four source-built banks through read_bank and expects layout sfx with exact groups. Every 0x76 tag records 1 sample, 48,000 Hz and codec 11.
    • 4096 streams: each stream has a 1-byte data tag and a 32-byte format tag. The header is 16 + 4 × 4096 + 16 × 4096 = 81,936 bytes, followed by 33 bytes per stream; the data and format tags of each stream touch. Expected: one group with 4,096 streams and 4,096 samples.
    • stream id 0x10000000: one stream whose word is 2 << 29 | 0x10000000.
    • data touching the format tag: data at 128..144, format at 144..176.
    • empty tag inside the format tag: a zero-length 0xBD tag at offset 170, inside the format tag at 160..192.
  • test_music_accepts_limits gains two cases: stream 1 with ID 0x10000000, and a zero-length 0xBD tag on the ID-0 stream at offset 100, inside the music header at 64..140. Both expect the existing MUSIC_FORMATS and four channels.

Verification

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

> python -B tests/awc_metadata_check.py
Ran 14 tests in 1.049s
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.

Before this change the check ran 13 tests and passed. With each of M1-M9 applied, the new check fails in exactly the subtest named in the table. M1-M4, M6-M9 fail with ValueError (or IndexError for M2) raised from an acceptance case, and M5 fails because no exception is raised for the empty data tag.

Evidence and follow-up

  • M10 is not pinned. header_size == table means that no stream has a tag, and the original then rejects the bank with "Expected one data tag ..." (sound effects) or "Expected one 0x48 music header ..." (music). The mutant rejects the same bank with a different message, so the two differ only in wording.
  • I did not probe the 28-bit length and offset masks of the tag word. A case that distinguishes them needs a range larger than 128 MiB.
  • With the stream count of 0, the CLI exits 1 with the specific message today. The new case keeps it from regressing to an uncaught IndexError.

The tool is not changed. All fixtures are synthetic and built inside the test.

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 requirement changed.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589569347 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1837). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T19:20:28Z. --- ## Change `tests/awc_metadata_check.py` exercised the AWC reader's rejections well, but several documented acceptance boundaries in `tools/awc_metadata.py` had no case. A single-point change to each of them left the check green: - the 4,096-stream limit for sound-effect banks (only 4,097 was rejected); - the lower bound of the stream count (a count of 0 reaches `entries[0]` and raises `IndexError` instead of the specific `ValueError`); - the 29-bit stream ID: `entry & 0x1fffffff` decides between a sound-effect bank and a streamed music bank, and detects a second ID-0 stream in a music bank. ID `0x10000000` sets only bit 28; - "one nonempty data tag" for a sound-effect stream (only the music path had an empty-data-tag case); - the exclusion of empty tags from the overlap check (`if length:`), in both paths; - half-open extents in the sound-effect path: a data tag that ends where the format tag begins is not an overlap (the music path already had this case). I applied 14 single-point mutants by hand to `tools/awc_metadata.py`, ran the check after each and reverted: | Mutant | Existing check | With the new cases | |---|---|---| | M1 `1 <= count <= 4096` -> `< 4096` | survived | killed (`4096 streams`) | | M2 `1 <= count` -> `0 <= count` | survived | killed (`empty stream table`) | | M3 `read_bank`: `entries[0] & 0x1fffffff` -> `0x0fffffff` | survived | killed (sfx `stream id 0x10000000`) | | M4 `read_formats`: `entries[0] & 0x1fffffff == 0` -> `0x0fffffff` | survived | killed (sfx `stream id 0x10000000`) | | M5 sfx: `kind == 0x55 and length` -> `kind == 0x55` | survived | killed (`empty data tag`) | | M6 sfx: `if length:` before `spans.append` -> always | survived | killed (`empty tag inside the format tag`) | | M7 sfx overlap `left[1] > right[0]` -> `>=` | survived | killed (`data touching the format tag`, `4096 streams`) | | M8 music duplicate-ID mask `0x1fffffff` -> `0x0fffffff` | survived | killed (music `stream id 0x10000000`) | | M9 music: `if length:` before `spans.append` -> always | survived | killed (`empty tag inside the music header`) | | M10 `table <= header_size` -> `table < header_size` | survived | survived (see below) | | M11 music overlap `>` -> `>=` | killed | killed | | M12 sfx extent check reduced to `header_size <= start` | killed | killed | | M13 sfx `samples +=` -> `samples =` | killed | killed | | M14 flag word `0xff020001` dropped | killed | killed | The new cases: - `test_rejects_invalid_metadata` gains two patches of the existing fixture: a stream count of 0, and the first sound's data tag set to length 0 (that sound keeps its `0x76` tag, so it has no nonempty data tag). - New `test_sfx_accepts_limits` reads four source-built banks through `read_bank` and expects layout `sfx` with exact groups. Every `0x76` tag records 1 sample, 48,000 Hz and codec 11. - `4096 streams`: each stream has a 1-byte data tag and a 32-byte format tag. The header is 16 + 4 × 4096 + 16 × 4096 = 81,936 bytes, followed by 33 bytes per stream; the data and format tags of each stream touch. Expected: one group with 4,096 streams and 4,096 samples. - `stream id 0x10000000`: one stream whose word is `2 << 29 | 0x10000000`. - `data touching the format tag`: data at 128..144, format at 144..176. - `empty tag inside the format tag`: a zero-length `0xBD` tag at offset 170, inside the format tag at 160..192. - `test_music_accepts_limits` gains two cases: stream 1 with ID `0x10000000`, and a zero-length `0xBD` tag on the ID-0 stream at offset 100, inside the music header at 64..140. Both expect the existing `MUSIC_FORMATS` and four channels. ## Verification Based on `origin/main` 813045b3c13f7bad20d8577557b621ee869ccbba. Windows 11 Pro 26300.9974, Python 3.12.10, no build needed. ```text > python -B tests/awc_metadata_check.py Ran 14 tests in 1.049s 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. ``` Before this change the check ran 13 tests and passed. With each of M1-M9 applied, the new check fails in exactly the subtest named in the table. M1-M4, M6-M9 fail with `ValueError` (or `IndexError` for M2) raised from an acceptance case, and M5 fails because no exception is raised for the empty data tag. ## Evidence and follow-up - M10 is not pinned. `header_size == table` means that no stream has a tag, and the original then rejects the bank with "Expected one data tag ..." (sound effects) or "Expected one 0x48 music header ..." (music). The mutant rejects the same bank with a different message, so the two differ only in wording. - I did not probe the 28-bit length and offset masks of the tag word. A case that distinguishes them needs a range larger than 128 MiB. - With the stream count of 0, the CLI exits 1 with the specific message today. The new case keeps it from regressing to an uncaught `IndexError`. The tool is not changed. All fixtures are synthetic and built inside the test. ## 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 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
tedin7 commented 2026-11-24 20:00:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:33:21Z.

Review: COMMENTED


Reviewed tests/awc_metadata_check.py at commit 9314b151b96bff0579d5b46958340fff405f6003 against tools/awc_metadata.py (_header, read_formats, _music, read_bank). All new assertions pin real stream-table limits (0 refused, 4096 accepted), empty-data-tag refusal, 29-bit stream ID mask (0x10000000), touching tag spans, and zero-length tags inside format/music headers; clean-room and title-neutral, 0 P1/P2 defects found.

Linux verification

  • git diff --check origin/main...HEAD — passed
  • python -B tests/bidi_controls_check.py — passed (1320 files checked)
  • python -B tests/awc_metadata_check.py -v — 14/14 tests passed (0.650s)

Windows Server 2025 verification (Build 26100, MSVC 14.44.35207 + D3D12 WARP)

  • Debug (--preset dev): ctest --preset dev -R '^audio_awc_metadata$' --parallel 6 --no-tests=error --output-on-failure — 1/1 passed (0.67s)
  • Release /O2 (--preset release): ctest --preset release -R '^audio_awc_metadata$' --parallel 6 --no-tests=error --output-on-failure — 1/1 passed (0.67s)

Local mutation checks

  • Mutated tools/awc_metadata.py in read_bank from entries[0] & 0x1fffffff to 0x0fffffff: python -B tests/awc_metadata_check.py failed (rc=1, killed).
  • Mutated tools/awc_metadata.py in read_formats overlap check from left[1] > right[0] to left[1] >= right[0]: python -B tests/awc_metadata_check.py failed (rc=1, killed).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045997389 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1837#pullrequestreview-6045997389). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:33:21Z. **Review:** COMMENTED --- Reviewed `tests/awc_metadata_check.py` at commit `9314b151b96bff0579d5b46958340fff405f6003` against `tools/awc_metadata.py` (`_header`, `read_formats`, `_music`, `read_bank`). All new assertions pin real stream-table limits (0 refused, 4096 accepted), empty-data-tag refusal, 29-bit stream ID mask (`0x10000000`), touching tag spans, and zero-length tags inside format/music headers; clean-room and title-neutral, 0 P1/P2 defects found. ### Linux verification - `git diff --check origin/main...HEAD` — passed - `python -B tests/bidi_controls_check.py` — passed (1320 files checked) - `python -B tests/awc_metadata_check.py -v` — 14/14 tests passed (`0.650s`) ### Windows Server 2025 verification (Build 26100, MSVC 14.44.35207 + D3D12 WARP) - **Debug (`--preset dev`)**: `ctest --preset dev -R '^audio_awc_metadata$' --parallel 6 --no-tests=error --output-on-failure` — **1/1 passed** (`0.67s`) - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^audio_awc_metadata$' --parallel 6 --no-tests=error --output-on-failure` — **1/1 passed** (`0.67s`) ### Local mutation checks - Mutated `tools/awc_metadata.py` in `read_bank` from `entries[0] & 0x1fffffff` to `0x0fffffff`: `python -B tests/awc_metadata_check.py` failed (`rc=1`, killed). - Mutated `tools/awc_metadata.py` in `read_formats` overlap check from `left[1] > right[0]` to `left[1] >= right[0]`: `python -B tests/awc_metadata_check.py` failed (`rc=1`, killed). AI-assisted; commands listed were executed locally.
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!1830
No description provided.