Skip to content

wave64_pipeline_audit: reject non-standard JSON constants, RecursionError, and invalid assess() entries - #5079

Open
tomgamer22 wants to merge 2 commits into
ItsNotRexed:mainfrom
tomgamer22:fix-wave64-pipeline-audit-json
Open

tomgamer22 wants to merge 2 commits into
ItsNotRexed:mainfrom
tomgamer22:fix-wave64-pipeline-audit-json

Conversation

@tomgamer22

Copy link
Copy Markdown
Contributor

Summary

Claimed in #5032 (comment) (new BUILD item).

What failed

  • tools/wave64_pipeline_audit.py:152-157 (load_json) called json.load(source) without a parse_constant hook, accepting non-standard JSON constants (NaN, Infinity, -Infinity), and only caught (OSError, ValueError), leaving deeply nested JSON (e.g. "[" * 2000) able to raise RecursionError uncaught in load_json and main() (including via --manifest / load_pipeline_manifest) instead of reporting a one-line wave64_pipeline_audit: error and exiting 2.
  • tools/wave64_pipeline_audit.py:66,85 (assess) accessed entry["stage"] and STAGE_BITS[stage] directly without validating entry is a dict with "stage" in STAGE_BITS, raising uncaught TypeError/KeyError instead of ValueError.

Fix

  • Added _reject_constant (parse_constant=_reject_constant) to json.load in load_json() and caught (OSError, ValueError, RecursionError) in both load_json() and main().
  • Validated isinstance(entry, dict) and entry.get("stage") in STAGE_BITS at the start of assess(), raising ValueError.
  • Added unit tests in tests/test_wave64_pipeline_audit.py (DecisionTest and CommandLineTest) covering deeply nested JSON in index, --device-info, and --manifest, non-standard JSON constants (NaN, Infinity, -Infinity), and invalid/missing stage or non-dict entry.

Testing

  • python -I tests/test_wave64_pipeline_audit.py — Ran 18 tests in 3.655s — OK
  • git diff --check — clean

No GPU or game files were used; only synthetic Python CPU unit tests were run.

AI-assisted (Antigravity).

Generated by Antigravity (Gemini).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 0a72628c2 on Windows 11: pytest tests/test_wave64_pipeline_audit.py -q -> 18 passed, 43 subtests passed; git diff --check clean.

wave64_pipeline_audit now rejects non-standard JSON constants (NaN/Infinity), a RecursionError from a deeply nested document, and invalid assess() entries with one ERROR: line instead of a traceback or a silently accepted report; the added cases cover each shape and the valid audit. No blocking issue.

@ErayOzdayioglu

Copy link
Copy Markdown

Tested 0a72628 on Windows 11 26200, CPython 3.12.10 (CPU only, synthetic inputs, no game files): pass, with two notes on the tests.

  • python -I tests/test_wave64_pipeline_audit.py: 18 tests, OK.
  • Control, the PR's tests against main's tools/wave64_pipeline_audit.py: 7 failures and 5 errors, all in test_assess_rejects_non_dict_and_invalid_or_missing_stage and test_rejects_non_standard_json_constants. So those two tests do cover the change.
  • Note 1, RecursionError: it is a subclass of RuntimeError, which main() on main already catches. With a 100,000-deep [[[...]]] as the index, as --device-info and as --manifest, main's tool already prints one wave64_pipeline_audit: maximum recursion depth exceeded ... line and exits 2, without a traceback. The new except clauses only add the cannot read JSON input <path>: prefix in load_json. Also, test_rejects_deeply_nested_json_inputs passes on main as well: 2,000 levels parse fine on 3.12, and the input is then rejected by the existing shape checks (expected a translator index object ..., Device.read). It never reaches a RecursionError. A depth such as 100,000 would exercise the decoder limit.
  • Note 2, the assess() guard can't be reached from the command line: build_report only selects rows whose stage is in GRAPHICS, and manifest mode requires the row's stage to match the manifest's. So test_invalid_or_missing_stage_in_index_cli_reports_error also passes on main (it exits 2 with "no graphics shaders"). The guard is still worth having for direct callers, and the unit test covers that.
  • Minor: --manifest is read by shader_link_check.load_pipeline_manifest, which has no parse_constant, so NaN/Infinity there still parse. That looks harmless for a manifest of paths and stages.

Code read: the change is correct and safe. Neither note blocks it; they only affect what the new tests prove.

AI-assisted: yes

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 0a72628 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_wave64_pipeline_audit.py -> Ran 18 tests, OK
  • Negative control (tools/wave64_pipeline_audit.py swapped to upstream/main): FAILED (failures=7, errors=5)

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

…udit-json

# Conflicts:
#	tools/wave64_pipeline_audit.py
@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 0650d634 merged onto main 511e3826 on Windows 11, CPython 3.14.3, CPU only: pass.

  • python -I tests/test_wave64_pipeline_audit.py: 18 tests OK.
  • Negative control (tools/wave64_pipeline_audit.py from main, the PR's tests kept): tests/test_wave64_pipeline_audit.py 18 tests FAILED (failures=7, errors=5).
  • py_compile on the 2 changed Python files: OK; git diff --check: clean.

No game files. AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 0650d63 merged with main 00f5ce6 on Linux (WSL2), CPython 3.12.16 with -I: pass. The merge was clean; tests/test_wave64_pipeline_audit.py ran 18 tests, OK. Negative control: with tools/wave64_pipeline_audit.py reverted to main's version, the test fails (7 failures, 5 errors); restored afterwards.

@Arkex-ai

Copy link
Copy Markdown
Contributor

Coordination question about duplicate shader names in the input index. On Windows I reproduced the same behavior on main (dde82f2) and this PR (0650d63), using a synthetic index and a device with a fixed subgroup size of 32. Two top-level members named demo describe different pixel shaders: one exact, one approximate. With --strict, putting the approximate entry last returns 1, while reversing the same members returns 0. Each single-entry control returns the expected result.

Are you already planning to handle repeated shader names in this PR? We can contribute a focused follow-up with both orderings as regression tests. We are holding off on a claim since the JSON loader and test file overlap.

@jpjonte

jpjonte commented Nov 23, 2026

Copy link
Copy Markdown

Tested 0650d63 merged onto main 1924c8f on AMD RX 9070 XT (RDNA4, gfx1201, wave32 and wave64), RADV Mesa 26.3.1, Arch Linux (kernel 7.3.5), Python 3.14: pass.

  • The PR's own tests: tests/test_wave64_pipeline_audit.py: 18 tests, OK.
  • Semantic suite: no change from main 1924c8f. The 48 failures there are the stale test_image_atomics_guard / test_image_store_d16 tests that tests: fix image atomics guard and image_store d16 tests after #4473 and #6805 #7608 fixes, and this PR adds none.
  • compileall: OK. scripts/run_gpu_tests.py: 245/245 translated, all spirv-val-valid, 222/239 passed, 16 skipped. runtime/test/shaders/check.py: 207 of 210 pass, 3 skipped. Same per-test results as main, apart from ms_wave_info_s3, a mesh-shader fixture that fails intermittently on main on this GPU as well, unrelated to this PR.

No game files. AI-assisted (Claude Code).

@karearl

karearl commented Nov 23, 2026

Copy link
Copy Markdown

Hardware: AMD Radeon Graphics gfx1036 (Raphael iGPU, Windows driver 32.0.11024 / 24.10.24, wave64, maxPushConstantsSize 128, run with LEONIDA_PC_TAIL_UBO=1) and RTX 5080 (NVIDIA 621.24, wave32, native and LEONIDA_W64_EMULATE=1), Windows 11 IoT Enterprise LTSC 2024, MSVC 2022, llvm-mc 21.1.8, SPIRV-Tools v2026.4.

Baseline on main 3e1e6ea11 on this machine: run_gpu_tests.py fails ms_clip (AMD) and ms_wave_info_s3 (both GPUs); run_semantic_tests.py fails test_image_atomics_guard and test_image_store_d16. PRs on an older base also fail test_float_nan_fract, which #7302 fixed on main. "Same as main" below means exactly these.

AI-assisted (Claude Code).

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 0650d634 on Linux, CPython 3.14, CPU only, synthetic inputs, merged onto main 867d922f: pass

  • python -I tests/test_wave64_pipeline_audit.py: Ran 18 tests, OK. With only the non-test files reverted to main: FAILED (failures=7, errors=5), so the new tests exercise the change.
  • compileall and scripts/check_no_game_data.py on the changed files: clean.

From the agent's CLI run, which I did not repeat: at a nesting depth that raises, main already exits 2 with one line for this tool, because its existing except catches RuntimeError; the failures without the change are the PR's other new cases.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants