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

Closed
leonida/mandy
alexandersato0830 wants to merge 0 commits from codex/shader-index-surrogate-pairs into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

alexandersato0830 commented 2026-11-25 18:56:38 +00:00

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.
Claimed in the coordination issue as: [SHADER-INDEX-SURROGATE-PAIRS](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171580986) ### 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](https://www.rfc-editor.org/rfc/rfc8259#section-7) ### 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 - [x] Based on current `main`. - [x] One topic. - [x] No game data, keys or decryption.
zmasi commented 2026-11-28 12:24:18 +00:00

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.

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: ```text 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(...)`: ```cpp 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 commented 2026-11-29 02:41:42 +00:00

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).

**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).
fiestorra commented 2026-11-30 08:10:05 +00:00

Independent verification on this machine (Windows 11, MSVC 19.44.35226): this pull request does not compile, and the reason is a Windows-specific one worth knowing.

1. It applies. merge-tree clean; the commits cherry-pick onto main bbd45f5cc without a conflict.

2. Building its test target:

cmake --build runtime/build-ninja --target shader_library_test
shader_library_test.cpp(646): error C3850: '\uD834': a universal character name cannot designate a character in the basic source character set
shader_library_test.cpp(646): error C3850: '\uDD1E': a universal character name cannot designate a character in the basic source character set

What that means: the line contains a \uD834\uDD1E pair - a surrogate pair spelling a non-BMP character (the musical G clef, U+1D11E, if the pair is what I think). MSVC rejects lone surrogates in \u escapes: C++ requires a single \U0001D11E for a code point above U+FFFF, or the character written directly in a UTF-8 source file with /utf-8 set.

So the fix is mechanical: "\uD834\uDD1E" -> "\U0001D11E" (or the literal character). This is a Windows-only failure - which is exactly the kind that a Linux-only CI would not catch, and this test target is compiled by the Windows job.

What I did not test: anything beyond the compile. The target never linked, so its assertions never ran.

How it was found: a sweep of all 115 open pull requests from 11-25 that touch a C++ test, applying each to main, building the test target and running it through ctest -R. 39 built and passed; this is one of the two that do not build.

Written with an AI assistant.

Independent verification on this machine (Windows 11, MSVC 19.44.35226): **this pull request does not compile**, and the reason is a Windows-specific one worth knowing. **1. It applies.** `merge-tree` clean; the commits cherry-pick onto `main` `bbd45f5cc` without a conflict. **2. Building its test target:** ``` cmake --build runtime/build-ninja --target shader_library_test shader_library_test.cpp(646): error C3850: '\uD834': a universal character name cannot designate a character in the basic source character set shader_library_test.cpp(646): error C3850: '\uDD1E': a universal character name cannot designate a character in the basic source character set ``` **What that means:** the line contains a `\uD834\uDD1E` pair - a **surrogate pair** spelling a non-BMP character (the musical G clef, U+1D11E, if the pair is what I think). MSVC rejects **lone surrogates** in `\u` escapes: C++ requires a single `\U0001D11E` for a code point above U+FFFF, or the character written directly in a UTF-8 source file with `/utf-8` set. **So the fix is mechanical:** `"\uD834\uDD1E"` -> `"\U0001D11E"` (or the literal character). **This is a Windows-only failure** - which is exactly the kind that a Linux-only CI would not catch, and this test target is compiled by the Windows job. **What I did not test:** anything beyond the compile. The target never linked, so its assertions never ran. **How it was found:** a sweep of all 115 open pull requests from 11-25 that touch a C++ test, applying each to `main`, building the test target and running it through `ctest -R`. **39 built and passed; this is one of the two that do not build.** Written with an AI assistant.
aslan2142 commented 2026-12-01 16:41:32 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.