textures: harden paged_resource validation and add unit suite #2668
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2676"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T01:45:48Z.
Change
Harden input validation in
tools/paged_resource.pyand add a pure-Python unit, edge-case, and mutation suite (tests/paged_resource_check.py), registered inCMakeLists.txtastextures_paged_resource_check.booland non-intvalues (isinstance(v, bool) or not isinstance(v, int)) with explicitValueErrorforSegment(offset,stored,size) andPagedResource.read()(offset,length,limit).PagedResource.__init__()that every segmentcodecis a supported string ("raw"or"zlib"), and reject negativelimit < 0inPagedResource.read().ValueErrormessages and positive behavior across all callers (tools/texture_descriptors.py,tools/script_state_probe.py,tools/shader_census.py).Verification
Verified on commit
f69f1e7b(based onupstream/main82c70807) on Windows usingout/pe-env/Scripts/python.exe -B:out\pe-env\Scripts\python.exe -B tests\paged_resource_check.py-> exit 0 (6/6 tests OK, 0 skips: multi-segment raw+zlib boundary spans, short-read_read_atreassembly, bool/non-int/overlapping/descending/empty/oversized/bad-codec/bad-raw-size rejections, corrupt/truncated/trailing-data/over-limit zlib, negative/bool/overflowread()bounds, and 5 fast in-memory mutations).tests\texture_descriptors_check.py,tests\awc_metadata_check.py(14 OK),tests\resource_root_check.py(5 OK),tests\sgd5_effects_check.py(4 OK) -> all exit 0.out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py,tests\docs_links_check.py,tests\bidi_controls_check.py-> all exit 0.tests/paged_resource_check.py): allowingboolin_require_int(), skipping upfront codec validation in__init__(), and allowing negativelimitinread().Evidence and follow-up
BytesIO/ short-read streams constructed at runtime (MIT License; no external data or binaries).Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T01:56:42Z.
Fixed the Linux CI failure in
tests/resource_ranges_check.py(commitf9ac2505):PagedResource.__init__()now rejects only non-str/empty codecs upfront and defers unknown string codecs (such as"other") toPagedResource.read()so segments following an unknown codec remain independently addressable as tested bytest_invalid_segmentsand documented indocs/experiments.md. Updatedtests/paged_resource_check.pyto cover both upfront non-str/empty rejections and deferred unknown-codecread()failures.Verified locally with
tests/resource_ranges_check.py(21 OK),tests/paged_resource_check.py(6 OK), caller suites (texture_descriptors_check,awc_metadata_check,resource_root_check,sgd5_effects_check,script_state_check,shader_census_check),tests/form_coverage_check.py,tests/docs_links_check.py, andtests/bidi_controls_check.py(all exit 0). AI-assisted.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:01:39Z.
Review: COMMENTED
Review of head
3ff83f28(after merging current main).Looks sound:
tools/paged_resource.py: bool/non-int rejection forSegmentfields andread()args, upfront codec check, negativelimitrejected. Existing error messages and positive behavior are unchanged.tests/paged_resource_check.pycovers boundary spans, short reads, corrupt/truncated zlib, bad bounds and in-memory mutations. It is registered astextures_paged_resource_checknext to its sibling Python checks.paged_resource.Commands run locally (Linux, worktree at this head):
python3 -B tests/paged_resource_check.py-> 6 tests OKpython3 -B tests/resource_ranges_check.py,tests/texture_descriptors_check.py,tests/docs_links_check.py,tests/bidi_controls_check.py-> exit 0git diff --check origin/main...HEAD-> cleanboolrejection in_require_int-> new test fails (7 failures)limit < 0check inread()-> new test fails (1 failure)Windows receipt follows separately.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:11:38Z.
Win2025 WARP receipt for head
3ff83f28after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
3ff83f2878ba633c1cbc97db5e0b4d9ea4fb3ff2:--preset dev):cmake --build --preset dev -- -j 2):121.41s(configure3.38s)ctest --preset dev -R 'textures_paged_resource_check|layout_chunk_summary' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (1.26s:textures_paged_resource_check0.30s,layout_chunk_summary1.06s)/O2(--preset release):cmake --build --preset release -- -j 2):231.92s(configure3.38s)ctest --preset release -R 'textures_paged_resource_check|layout_chunk_summary' --parallel 2 --no-tests=error --output-on-failure): 2/2 passed (1.50s:textures_paged_resource_check0.37s,layout_chunk_summary1.26s)tests/resource_ranges_check.pyok (1.0s)sccache: 143/207 hits; wall372.4sAI-assisted; commands listed were executed locally.