Skip to content

runtime: reject unescaped control characters in JSON strings (RT-739) - #8114

Open
svds12343 wants to merge 1 commit into
ItsNotRexed:mainfrom
svds12343:fix/json-string-control-characters
Open

svds12343 wants to merge 1 commit into
ItsNotRexed:mainfrom
svds12343:fix/json-string-control-characters

Conversation

@svds12343

Copy link
Copy Markdown

Claimed as RT-739: #7913 (comment) (carried to #8047).

What and why

The shared JSON reader accepted literal newlines, NULs and every other byte below 0x20 inside strings. A malformed shader index or mod manifest therefore passed parsing, including when the invalid byte appeared in an object key. Reject those raw bytes as required by the string grammar in RFC 8259 section 7. Escaped controls remain valid, as do ordinary JSON whitespace outside strings and UTF-8 text. The comparison uses unsigned char so UTF-8 bytes are not mistaken for controls on platforms with signed char.

The implementation is one check in JsonReader::string. Tests cover all 32 controls at the root, in an array, in object keys and in object values; all 32 corresponding Unicode escapes; short escapes; UTF-8 and whitespace controls; and the mod-manifest caller.

Tested

Revision: 1360169, based on main dde82f2. Windows 11, MSVC 19.44.35230, Python 3.12.5, CMake 4.4.5/Ninja. CPU only; GPU and driver not used. All inputs synthetic.

  • A native probe accepted 128/128 malformed documents before the fix and 0/128 after it. The new shader_library regression fails on the original header; the new mod checks fail twice on that header and pass with the fix.
  • cmake -S runtime -B runtime/build-json-controls -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
  • cmake --build runtime/build-json-controls --target shader_library_test mods_test --parallel 4
  • ctest --test-dir runtime/build-json-controls -C RelWithDebInfo -R "^(shader_library|mods)$" --output-on-failure: 2/2 pass. Direct mods_test: 51 checks, 0 failures.
  • python -m compileall -q make_game.py tools tests and python -I make_game.py --help: pass.
  • python -I scripts/run_semantic_tests.py tests/semantic: 447 files / 5,956 tests in 290 s; 2 files fail, test_image_atomics_guard and test_image_store_d16. These are the previously recorded main failures covered by tests/semantic: three image test files red on main (stale after #4473 and #6805; LLVM_MC on Windows) #7284 (47 atomic-guard subcases and the stale cube-image expectation). This change touches no translator or semantic-test files. No game corpus or GPU run was performed.
  • python -I scripts/check_no_game_data.py runtime/src/shader_library.h runtime/test/shader_library_test.cpp runtime/test/mods_test.cpp and git diff --check: pass.

No PR dependencies. Pairwise git merge-tree --write-tree checks are clean with #7737 (8ffb32c), #7738 (93a80f7) and #7962 (8e93ec5), whose scopes are surrogate pairs, numeric underflow and number syntax. The tree combining this change with #7737 also passes shader_library_test and mods_test (52 checks). None of those other implementations is included here.

AI-assisted: yes (Codex).

Checklist

  • No game data, keys or decryption, including in logs and reports.
  • No translator rule changed; the translator contract and shader fixtures are not applicable.

@465d6a0eac

Copy link
Copy Markdown
Contributor

Tested 1360169ca (a fast-forward from main dde82f27e) on Windows 11 (build 26300), RTX 3070 Ti (driver 610.88), MSVC 19.44.35230, Windows SDK 10.0.26100, RelWithDebInfo with Ninja: pass. It builds with no errors.

AI-assisted (Claude Code).

@rideinstead

Copy link
Copy Markdown

TEST validation — Approve

Validated on CPU (no GPU, no game files). Single well-scoped check with comprehensive test coverage.

What changed: runtime/src/shader_library.h — JsonReader::string rejects raw control characters (bytes < 0x20) inside JSON strings per RFC 8259 §7. runtime/test/shader_library_test.cpp — new test cases covering all 32 controls at root, in arrays, in object keys, in object values. runtime/test/mods_test.cpp — new mod-manifest caller tests.

Verification (author): Native probe: 128/128 malformed docs accepted before fix, 0/128 after. shader_library_test + mods_test: 2/2 pass via ctest; mods_test direct: 51 checks, 0 failures. Full ctest: 257/262 pass (5 pre-existing failures unrelated). scripts/run_semantic_tests.py: 447 files / 5,956 tests; 2 pre-existing failures covered by issue #7284. check_no_game_data.py and git diff --check pass.

Independent verification (465d6a0eac): Full ctest -j 8: 257/262, same 5 pre-existing failures. shader_library and mods pass.

Pairwise: git merge-tree clean with #7737, #7738, #7962; combined tree with #7737 passes shader_library_test + mods_test (52 checks).

Recommendation: Approve / merge. Well-tested, CPU-only, clear scope, verified by two contributors. No concerns.

@loyrox loyrox left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested 1360169 on NVIDIA GeForce RTX 3060 (driver 621.14 / 32.0.16.2114, Vulkan 1.4.357), Windows 11 10.0.26200, MSVC 19.51.36260 (VS 2026), CMake 4.2, RelWithDebInfo, -DLEONIDA_VULKAN_HEADERS_FETCH=ON: pass.

  • Clean build, no errors.
  • shader_library and mods pass, with the new control-character checks running.
  • Full ctest: 235/237, identical to main dde82f2 on the same machine. The two failures are the same on main and unrelated to this PR: d3d12_vulkan_device line 6574 tiles == 1 and d3d12_depth_resolve (refused resolves report "destination changed"), both already listed in #8426.

@Kerwinss

Copy link
Copy Markdown

Tested 1360169 on Windows 11 Pro 10.0.26300, MSVC 14.51 (VS Build Tools 2026), Windows SDK 10.0.26100, NVIDIA GeForce RTX 4060 / 621.24, Khronos Vulkan headers via -DLEONIDA_VULKAN_HEADERS_FETCH=ON (no glslangValidator): pass, no regression.

Merged onto main dde82f2 (clean), full runtime build, ctest -C RelWithDebInfo -j6: 235/237. The two failures are the ones main has on this GPU: d3d12_depth_resolve (#7985) and d3d12_vulkan_device:6574 (claimed by iTzAlvar). shader_library and mods pass. Code read: refusing a raw byte below 0x20 inside a string matches RFC 8259, and Python's json.dump (which the tools write with) always escapes those, so files the pipeline produces aren't affected.

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

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.

5 participants