Validate shader records and output stems in extract_shaders #191
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/192"
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 alexander-src on 2026-11-21T18:12:18Z.
Change
Harden record scanning,
XBCHvalidation, and output filename disambiguation intools/extract_shaders.py:cursoror incrementingtotal_found: enforce32 <= decoded <= 16 << 20, inflate raw DEFLATE via boundedzlib.decompressobj(-15)(decoded + 1) checkinglen(blob) == decoded and stream.eof, and require validparts(blob)plus a 24-byteDXILheader (matchingtools/resource_inventory.py::scene_records). Previously, a false-positive ASCII header with matchingstored == repeatedjumpedcursorpast up to 8 MiB of valid shader records and inflatedtotal_found.XBCHentry bounds (offset >= table_idx + 12 + count * 12) and decodedFSSMpayload length against theXBCHheader size field inextract_native_rdna2_codeusing boundedzlib.decompressobj(15)(matchingtools/pixel_aot.py).mmap.mmapso empty files emit an emptymanifest.jsoninstead of raisingValueError.PS_Dup,PS_Dup_1) and case variants (ps_dupon Windows) do not overwrite earlier outputs, avoid writing.dxbctwice under--format bothwhen native code is absent, and expose allSTAGE_NAMESstages in--stage.tests/rdna2_tools_check.py.Verification
Run on Linux x86_64 (
python3 3.14) at branch HEAD (againstmainccfa703):python3 -B tests/rdna2_tools_check.py->Ran 16 tests in 0.339s : OK (skipped=1)(test_llvm_comparisonskipped becauseLLVM_LIBis unset; all 15 non-LLVM tests passed).python-linuxsuite (script_state_check.py,bcpack_check.py,resource_ranges_check.py,dxcontainer_part_offsets_check.py,layout_chunks_check.py,intake/paths_check.py,shader_probe_check.py,rdna2_tools_check.py) +tests/gpu_report_format_check.py: all passed.main:tools/extract_shaders.pyproduced 3 failures and 1 error (ValueError: cannot mmap an empty file, skipped valid record after false header, collidingPS_Dup_1.bin/ps_dup.binoutputs, and accepted mismatchedXBCHsize).build-and-testjob and Ubuntullvm-15job (missing Windows host andllvm-15package locally; covered by CI).Evidence and follow-up
All new fixtures in
tests/rdna2_tools_check.pyare synthetic byte sequences constructed in-memory by the existingenvelope()helper (same MIT license as the repository). No game files or external dumps were used.Checklist
AI-assisted: yes.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T18:14:10Z.
The new check defers cursor advancement until after a valid DXIL record, but
stream.eofcan also be true withstream.unused_datastill insidestored. In that casecursor = start_payload + storedstill skips the following valid record. Please cover a valid raw-DEFLATE stream followed by another envelope inside an oversized claimed span, and ensure that second record is found. If the format permits padding, bound cursor advancement to the bytes actually validated.Imported from R0Y00/Xbox2Windows. Originally posted by alexander-src on 2026-11-21T18:32:00Z.
Good catch, fixed in
671a9e5.extract_shaders()now advancescursorbystored - len(stream.unused_data)so it only steps past the validated raw-DEFLATE bytes and still scans any trailing data inside an oversized claimed span. Addedtest_oversized_claimed_span_with_unused_data_does_not_skip_following_recordintests/rdna2_tools_check.py(confirmed it fails one9e6118and passes on671a9e5, 17 tests ran, 16 passed, 1 skipped withoutLLVM_LIB).