tooling: validate relocated resource root block-map pointer #448

Merged
agilesh08 merged 1 commit from upstream-pr/454 into main 2026-11-22 05:06:30 +00:00
agilesh08 commented 2026-11-22 04:32:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-22T04:32:03Z.


## Change

In tools/resource_root.py, inspect_root() checked the bounds of block_map via span(block_map, 1) but omitted the resulting 1-byte span from extents = sorted((schemas, blocks, root)). Consequently, a malformed PRD0 v0x7a resource where the block-map pointer aliased the schema table, the block directory, or the root instance passed validation undetected.

Because the full payload length of the block map is not explicitly defined in this profile, this change implements the narrower validation of the block-map pointer against the known table and root extents:

  1. Captures block_map_ptr = span(block_map, 1) and includes it in extents = sorted((block_map_ptr, schemas, blocks, root)) to validate that the block-map pointer does not fall within the schema directory, block directory, or root instance.
  2. Updates the error diagnostic to "Overlapping schema, block directory, block map pointer or root instance".
  3. Adds negative controls in tests/resource_root_check.py for block map header violations, out-of-bounds RVAs, buffer overruns, and pointer aliasing against schemas, block directory, and root instance.
  4. Adds a boundary test test_block_map_boundaries() verifying valid boundary placements of the block-map pointer immediately adjacent to each table and at the buffer boundary.
  5. Updates docs/experiments.md to note that the root and both directories must fit in disjoint spans and the block-map pointer must not fall within any of these extents.

Verification

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

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

Output:

test_block_map_boundaries (tests.resource_root_check.RootChecks.test_block_map_boundaries)
Check valid boundary placements of the block-map pointer adjacent to tables and the buffer end. ... ok
test_member_cli (tests.resource_root_check.RootChecks.test_member_cli) ... ok
test_nearby_root_and_invalid_directories (tests.resource_root_check.RootChecks.test_nearby_root_and_invalid_directories) ... ok
test_read_budget (tests.resource_root_check.RootChecks.test_read_budget) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.614s

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/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
python -B tests/gpu_report_format_check.py

Result: All 20 checks passed (exit code 0).

Evidence and follow-up

The test uses 100% synthetic in-memory fixtures generated via Python struct.pack_into() without external files or proprietary assets.

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:6538464196 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/454). Originally posted by [agilesh08](https://github.com/agilesh08) on 2026-11-22T04:32:03Z. --- ## Change In `tools/resource_root.py`, `inspect_root()` checked the bounds of `block_map` via `span(block_map, 1)` but omitted the resulting 1-byte span from `extents = sorted((schemas, blocks, root))`. Consequently, a malformed PRD0 v0x7a resource where the block-map pointer aliased the schema table, the block directory, or the root instance passed validation undetected. Because the full payload length of the block map is not explicitly defined in this profile, this change implements the narrower validation of the block-map pointer against the known table and root extents: 1. Captures `block_map_ptr = span(block_map, 1)` and includes it in `extents = sorted((block_map_ptr, schemas, blocks, root))` to validate that the block-map pointer does not fall within the schema directory, block directory, or root instance. 2. Updates the error diagnostic to `"Overlapping schema, block directory, block map pointer or root instance"`. 3. Adds negative controls in `tests/resource_root_check.py` for block map header violations, out-of-bounds RVAs, buffer overruns, and pointer aliasing against schemas, block directory, and root instance. 4. Adds a boundary test `test_block_map_boundaries()` verifying valid boundary placements of the block-map pointer immediately adjacent to each table and at the buffer boundary. 5. Updates `docs/experiments.md` to note that the root and both directories must fit in disjoint spans and the block-map pointer must not fall within any of these extents. ## Verification Run on Windows x64 with Python 3.14 (`D:\Xbox2Windows\.venv\Scripts\python.exe`): ```powershell python -B -m unittest -v tests/resource_root_check.py ``` Output: ```text test_block_map_boundaries (tests.resource_root_check.RootChecks.test_block_map_boundaries) Check valid boundary placements of the block-map pointer adjacent to tables and the buffer end. ... ok test_member_cli (tests.resource_root_check.RootChecks.test_member_cli) ... ok test_nearby_root_and_invalid_directories (tests.resource_root_check.RootChecks.test_nearby_root_and_invalid_directories) ... ok test_read_budget (tests.resource_root_check.RootChecks.test_read_budget) ... ok ---------------------------------------------------------------------- Ran 4 tests in 0.614s 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/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 python -B tests/gpu_report_format_check.py ``` Result: All 20 checks passed (exit code 0). ## Evidence and follow-up The test uses 100% synthetic in-memory fixtures generated via Python `struct.pack_into()` without external files or proprietary assets. 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:07 +00:00
R0Y00 commented 2026-11-24 06:48:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T04:37:04Z.


The implemented check reserves exactly one byte at block_map. A map starting one byte before the root passes even if its data continues into the root, and the new adjacency test accepts that layout. Please describe this as checking the block-map pointer against the known table/root extents, including in docs/experiments.md. If the map length is known for this profile, validate that length and add a crossing-boundary control instead. The current tests support the narrower pointer check.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7074279205 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/454#issuecomment-7074279205). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T04:37:04Z. --- The implemented check reserves exactly one byte at block_map. A map starting one byte before the root passes even if its data continues into the root, and the new adjacency test accepts that layout. Please describe this as checking the block-map pointer against the known table/root extents, including in docs/experiments.md. If the map length is known for this profile, validate that length and add a crossing-boundary control instead. The current tests support the narrower pointer check.
agilesh08 commented 2026-11-24 06:48:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-22T04:57:25Z.


@R0Y00 Thanks for the review!

The exact byte length of the PRD0 v0x7a block map payload is not documented or specified for this profile in docs/experiments.md or tools/resource_root.py. As you noted, the check reserves a 1-byte span (span(block_map, 1)), which validates that the pointer does not fall within the known table/root extents rather than bounding the full extent of the map.

I have updated the PR to accurately describe this narrower pointer check:

  • Updated docs/experiments.md to state: "The root and both directories must fit in disjoint spans, and the block-map pointer must not fall within any of these extents."
  • Updated the error diagnostic in tools/resource_root.py to "Overlapping schema, block directory, block map pointer or root instance" and variable naming to block_map_ptr.
  • Added docstring clarification to test_block_map_boundaries() in tests/resource_root_check.py.
  • Updated the PR title and description to reflect the pointer check.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7074472328 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/454#issuecomment-7074472328). Originally posted by [agilesh08](https://github.com/agilesh08) on 2026-11-22T04:57:25Z. --- @R0Y00 Thanks for the review! The exact byte length of the PRD0 v0x7a block map payload is not documented or specified for this profile in `docs/experiments.md` or `tools/resource_root.py`. As you noted, the check reserves a 1-byte span (`span(block_map, 1)`), which validates that the pointer does not fall within the known table/root extents rather than bounding the full extent of the map. I have updated the PR to accurately describe this narrower pointer check: - Updated `docs/experiments.md` to state: *"The root and both directories must fit in disjoint spans, and the block-map pointer must not fall within any of these extents."* - Updated the error diagnostic in `tools/resource_root.py` to `"Overlapping schema, block directory, block map pointer or root instance"` and variable naming to `block_map_ptr`. - Added docstring clarification to `test_block_map_boundaries()` in `tests/resource_root_check.py`. - Updated the PR title and description to reflect the pointer check.
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!448
No description provided.