Skip to content

Decode supplementary Unicode in shader index JSON (SHADER-INDEX-SURROGATE-PAIRS) - #2045

Open
alexandersato0830 wants to merge 1 commit into
ProjectLeonida:mainfrom
alexandersato0830:codex/shader-index-surrogate-pairs
Open

alexandersato0830 wants to merge 1 commit into
ProjectLeonida:mainfrom
alexandersato0830:codex/shader-index-surrogate-pairs

Conversation

@alexandersato0830

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-INDEX-SURROGATE-PAIRS

What and why

JSON writers can encode one character outside the Basic Multilingual Plane as two \u escapes. The shader index reader currently encodes those surrogate code units separately, producing invalid UTF-8. Join the pair into one Unicode code point before emitting UTF-8, and refuse an unpaired surrogate. This changes JSON decoding. PR #2043 handles the separate filesystem conversion. RFC 8259, String encoding

Tested

  • The new synthetic JSON regression fails on 9f9a7c5f3 and passes with the fix. It checks a supplementary object key, the highest Unicode code point as a value, and isolated, mismatched or truncated surrogate pairs.
  • Built shader_library_test and ran the CMake shader_library test in RelWithDebInfo on Windows 11 with MSVC 19.51. All cases passed.
  • git diff --check and the source-only check passed.

GPUs tested: n/a (CPU-only parser test)

AI-assisted: yes (Codex)

Checklist

  • Based on current main.
  • One topic.
  • No game data, keys or decryption.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Tested on Windows 11 (10.0.26200.9974) with MSVC 19.44.35228 (x64, /std:c++20 /utf-8 /EHsc /W4 /permissive- /O2) against main d48a957bb + 19a215108e (claim #2570#issuecomment-7239117859):

  • Production code audit (runtime/src/shader_library.h): Clean — hex_quad (text_.size() - pos_ < 4), UTF-16 surrogate-pair decoding (0xd800..0xdbff + \u + 0xdc00..0xdfff -> 4-byte UTF-8), and unpaired high/low surrogate rejection are all exact. check_no_game_data.py clean; merges cleanly alongside #2043.
  • Windows MSVC build blocker in runtime/test/shader_library_test.cpp:629: Unmodified shader_library_test.cpp fails to compile on MSVC 19.44 (cl /std:c++20 /utf-8 /EHsc) with:
    runtime\test\shader_library_test.cpp(629): error C3850: '\uD834': a universal-character-name specifies an invalid character
    runtime\test\shader_library_test.cpp(629): error C3850: '\uDD1E': a universal-character-name specifies an invalid character
    runtime\test\shader_library_test.cpp(629): error C3850: '\uDBFF': a universal-character-name specifies an invalid character
    runtime\test\shader_library_test.cpp(629): error C3850: '\uDFFF': a universal-character-name specifies an invalid character
    
    Because shader_library_test builds without /Zc:preprocessor, #condition inside CHECK(...) stringifies the raw string literal R"({"\uD834\uDD1E": "\uDBFF\uDFFF"})" without doubling \u, forming illegal surrogate UCNs in an ordinary string literal (whereas line 632 outside CHECK compiles cleanly).
  • Suggested 2-line fix & Red -> Green verification: Hoisting the literal outside CHECK(...):
    const char* pair_json = R"({"\uD834\uDD1E": "\uDBFF\uDFFF"})";
    CHECK(JsonReader(pair_json).parse(supplementary));
    compiles cleanly on MSVC 19.44, fails Red on d48a957bb (rc=1, line 632: value && value->string == "\xf4\x8f\xbf\xbf"), and passes Green on d48a957bb + 19a215108e (SHA-256, inflate (stored/fixed/dynamic), JSON, FSSM extraction, FSPX programs and index lookup OK, rc=0).

AI-assisted.

@OreoFR

OreoFR commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Verified by OreoFR

  • Base: main aa918e5d9 + PR head 19a215108
  • Test: ctest -R ^shader_library$
  • Red on main: not run: the updated test does not compile
  • Green with the PR: not run: shader_library_test.cpp line 629 fails to compile with MSVC (C3850: the surrogate escapes for U+D834 U+DD1E and U+DBFF U+DFFF inside the raw string literal are read as invalid universal character names)
  • Verdict: FAILS (the updated test does not build with MSVC; the surrogate pairs in that raw string need a spelling MSVC does not turn into universal character names)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

Note: shares runtime/src/shader_library.h, runtime/test/shader_library_test.cpp with the open #2566; a rebase may be needed if #2566 lands first.

AI-assisted (Claude Code, Claude Opus 5.5).

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.

3 participants