tooling: normalize malformed zlib errors in paged resource reader #462

Merged
agilesh08 merged 1 commit from upstream-pr/468 into main 2026-11-22 05:37:23 +00:00
agilesh08 commented 2026-11-22 05:28:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-22T05:28:35Z.


## Change

In tools/paged_resource.py, PagedResource.read() enforces size budgets, boundary checks, and decoded extent matching by raising ValueError on malformed segments. However, if a segment contains corrupted compressed bytes (e.g. invalid zlib header or illegal compression method), decoder.decompress() raised an unhandled zlib.error directly out of the reader.

This change:

  1. Wraps decoder.decompress() with try ... except zlib.error as exc: and raises ValueError("Invalid compressed segment or decoded extent") from exc, normalizing compressed corruption to the reader's standard ValueError contract.
  2. In tests/resource_ranges_check.py, adds an intact control test ensuring valid decompression continues to succeed, and adds a synthetic corrupted zlib payload test (b"not zlib") verifying ValueError("Invalid compressed segment or decoded extent") is raised instead of zlib.error.

Verification

Run on Windows x64 with Python 3.14 (D:\Xbox2Windows\.venv\Scripts\python.exe):

python -B -m unittest -v tests/resource_ranges_check.py

Output:

test_invalid_segments (tests.resource_ranges_check.ResourceChecks.test_invalid_segments) ... ok
test_logical_range_crosses_pages (tests.resource_ranges_check.ResourceChecks.test_logical_range_crosses_pages) ... ok
test_short_reads_of_intact_segments (tests.resource_ranges_check.ResourceChecks.test_short_reads_of_intact_segments) ... ok
Ran 17 tests in 2.141s

OK

Full platform-independent suite (20 checks including docs_links_check.py and bidi_controls_check.py):

python -B tests/script_state_check.py
python -B tests/resource_root_check.py
python -B tests/bcpack_check.py
python -B tests/bc7_blocks_check.py
python -B tests/bc7_tiles_check.py
python -B tests/form_coverage_check.py
python -B tests/resource_ranges_check.py
python -B tests/awc_metadata_check.py
python -B tests/sgd5_effects_check.py
python -B tests/dxcontainer_part_offsets_check.py
python -B tests/layout_chunks_check.py
python -B tests/dependency_paths_check.py
python -B tests/intake/paths_check.py
python -B tests/shader_probe_check.py
python -B tests/dxil_retarget_check.py
python -B tests/rdna2_tools_check.py
python -B tests/pso_readiness_check.py
python -B tests/xmem_attribute_scan_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py

Result: All 20 checks passed with exit code 0.

Evidence and follow-up

All fixtures are in-memory byte streams created with io.BytesIO and Python's standard zlib.compress.

This change is AI-assisted.

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.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6538875067 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/468). Originally posted by [agilesh08](https://github.com/agilesh08) on 2026-11-22T05:28:35Z. --- ## Change In `tools/paged_resource.py`, `PagedResource.read()` enforces size budgets, boundary checks, and decoded extent matching by raising `ValueError` on malformed segments. However, if a segment contains corrupted compressed bytes (e.g. invalid zlib header or illegal compression method), `decoder.decompress()` raised an unhandled `zlib.error` directly out of the reader. This change: 1. Wraps `decoder.decompress()` with `try ... except zlib.error as exc:` and raises `ValueError("Invalid compressed segment or decoded extent") from exc`, normalizing compressed corruption to the reader's standard `ValueError` contract. 2. In `tests/resource_ranges_check.py`, adds an intact control test ensuring valid decompression continues to succeed, and adds a synthetic corrupted zlib payload test (`b"not zlib"`) verifying `ValueError("Invalid compressed segment or decoded extent")` is raised instead of `zlib.error`. ## Verification Run on Windows x64 with Python 3.14 (`D:\Xbox2Windows\.venv\Scripts\python.exe`): ```powershell python -B -m unittest -v tests/resource_ranges_check.py ``` Output: ```text test_invalid_segments (tests.resource_ranges_check.ResourceChecks.test_invalid_segments) ... ok test_logical_range_crosses_pages (tests.resource_ranges_check.ResourceChecks.test_logical_range_crosses_pages) ... ok test_short_reads_of_intact_segments (tests.resource_ranges_check.ResourceChecks.test_short_reads_of_intact_segments) ... ok Ran 17 tests in 2.141s OK ``` Full platform-independent suite (20 checks including `docs_links_check.py` and `bidi_controls_check.py`): ```powershell python -B tests/script_state_check.py python -B tests/resource_root_check.py python -B tests/bcpack_check.py python -B tests/bc7_blocks_check.py python -B tests/bc7_tiles_check.py python -B tests/form_coverage_check.py python -B tests/resource_ranges_check.py python -B tests/awc_metadata_check.py python -B tests/sgd5_effects_check.py python -B tests/dxcontainer_part_offsets_check.py python -B tests/layout_chunks_check.py python -B tests/dependency_paths_check.py python -B tests/intake/paths_check.py python -B tests/shader_probe_check.py python -B tests/dxil_retarget_check.py python -B tests/rdna2_tools_check.py python -B tests/pso_readiness_check.py python -B tests/xmem_attribute_scan_check.py python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py ``` Result: All 20 checks passed with exit code 0. ## Evidence and follow-up All fixtures are in-memory byte streams created with `io.BytesIO` and Python's standard `zlib.compress`. This change is AI-assisted. ## 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. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-24 06:43:11 +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!462
No description provided.