Skip to content

shader_stage_manifest: read a carve or unpack index saved with a UTF-8 BOM (EGEN-STAGEMANIFEST-BOM) - #6922

Open
evilclanker9000 wants to merge 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/1-stagemanifest-bom
Open

evilclanker9000 wants to merge 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/1-stagemanifest-bom

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

tools/shader_stage_manifest.shader_stems() is the reader tools/fssm_unpack.py --carve-index and
tools/shader_disasm.py --unpack-index use for a carve's index.json and an unpack's fssm_index.json. It opened the
file as utf-8, so an index saved by a Windows editor (Notepad, PowerShell 5.1 > redirection) stopped at the first
character: json.load refuses the BOM as U+FEFF and the tool reported invalid JSON, which reads like a broken index
rather than an encoding the reader can handle. Every other index reader in tools/ (hashdict, world_index,
classify_carve, user_sgpr_census, spirv_stubs, root_spill_census) already decodes with utf-8-sig, so the same
file that works for one tool failed for these two. make_game.py's unpacked_shader_stems() swallowed the error and
re-ran the unpack, which is the same defect without the message.

The change is one line: read the index as utf-8-sig. It tolerates a BOM and nothing else; a malformed index behind a
BOM still raises ValueError.

Test

python -I tests/test_shader_stage_manifest.py

Before (test added, tool unchanged):

ERROR: test_reads_an_index_saved_with_a_utf8_bom
ValueError: ...carve_bom.json: invalid JSON: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)
Ran 15 tests in 0.861s
FAILED (errors=1)

After:

Ran 15 tests in 0.814s
OK

python -m compileall -q make_game.py tools tests exits 0.

The new case writes two hand-built indexes with a EF BB BF prefix (a carve index with file, an unpack index with
name), asserts both are read, and asserts that BOM + "[{bad" is still invalid JSON.

GPU: none needed; nothing on this path touches a GPU or game data.

Notes

  • I fixed the shared reader rather than the two callers, because both callers exist only to hand this function a path;
    the same BOM bit make_game.py in a second place (unpacked_shader_stems()), which now fails over to "unpack again"
    instead of returning None.
  • Commit order: the reader first, then the test, so each commit is green on its own.

AI-assisted.

…8 BOM

shader_stems() opened the index as utf-8, so a BOM (Notepad, PowerShell 5.1 '>' redirection) reached json.load as U+FEFF and the caller got 'invalid JSON'. json.load itself names the fix: decode with utf-8-sig. Every other index reader in tools/ (hashdict, world_index, classify_carve, user_sgpr_census, spirv_stubs) already does this, and fssm_unpack.py --carve-index and shader_disasm.py --unpack-index are the two callers that read that index.
…lformed JSON

The new case fails on main with 'invalid JSON: Unexpected UTF-8 BOM (decode using utf-8-sig)' and passes with the fix. The malformed index behind a BOM keeps failing, so only the BOM is tolerated.

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

tools/shader_stage_manifest.py:shader_stems() opens carve/unpack index JSON with encoding="utf-8-sig" instead of "utf-8". tests/test_shader_stage_manifest.py adds a case writing BOM-prefixed carve and unpack indexes (asserting both are read) plus a BOM + [{bad case that must still raise invalid JSON.

Why merge

fssm_unpack.py --carve-index and shader_disasm.py --unpack-index share this reader, so a BOM written by Notepad or PowerShell > previously read as invalid JSON; make_game.py swallowed it and needlessly re-ran the unpack. This fixes both callers in one place and matches every other index reader under tools/. Malformed content still errors; no game data or GPU needed.

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

tools/shader_stage_manifest.py:shader_stems() opens carve/unpack index JSON with encoding="utf-8-sig" instead of "utf-8". tests/test_shader_stage_manifest.py adds a case writing BOM-prefixed carve and unpack indexes (asserting both are read) plus a BOM + [{bad case that must still raise invalid JSON.

Why merge

fssm_unpack.py --carve-index and shader_disasm.py --unpack-index share this reader, so a BOM written by Notepad or PowerShell > previously read as invalid JSON; make_game.py swallowed it and needlessly re-ran the unpack. This fixes both callers in one place and matches every other index reader under tools/. Malformed content still errors; no game data or GPU needed.

@AsgerCode

Copy link
Copy Markdown

Tested dab31cf on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass. The branch now conflicts with main, because #6929 merged the same line (see below).

What I ran:

  • python -I tests/test_shader_stage_manifest.py: 15 tests, OK.
  • Suites of the callers: tests/test_fssm_unpack.py 46 OK, tests/test_shader_disasm.py 29 OK, tests/test_shader_stage_resume.py 46 OK.
  • Negative control (merge base tools/shader_stage_manifest.py, PR tests): test_reads_an_index_saved_with_a_utf8_bom errors with invalid JSON: Unexpected UTF-8 BOM (decode using utf-8-sig). The test catches the bug.
  • The three callers, each given a hand-built index with a UTF-8 BOM that lists a file that does not exist. fssm_unpack.py --carve-index and shader_disasm.py --unpack-index now stop at "declared ... file is missing", so the index was parsed. On main they stop at invalid JSON: Unexpected UTF-8 BOM. make_game.unpacked_shader_stems() returns {'cs_bloom_0'}, where main returns None.
  • git diff --check: clean. compileall: exit 0.
  • Merge with main at 1cc6e3c1: clean. Merge with main at ee31aea9: conflict in tools/shader_stage_manifest.py, on the comment above open() only. With main's side kept, the test file merges automatically, and test_shader_stage_manifest.py runs 16 tests, OK, with both BOM tests.

shader_stems(path, "file", ".dxbc") on hand-built files. The PowerShell files come from Windows PowerShell 5.1.26100 with -NoProfile. I read their first bytes with od.

index file main 1cc6e3c1 this PR
EF BB BF + valid JSON invalid JSON (BOM) read
BOM + whitespace + valid JSON invalid JSON (BOM) read
two BOMs invalid JSON invalid JSON
BOM only invalid JSON invalid JSON
BOM + [{bad invalid JSON invalid JSON
Out-File -Encoding utf8, Set-Content -Encoding UTF8 (EF BB BF) invalid JSON (BOM) read
Set-Content, default (no BOM) read read
> and Out-File, default (FF FE, UTF-16 LE) invalid UTF-8 invalid UTF-8

Corrections, none blocking:

  1. The description and the new test comment say that PowerShell 5.1 > writes the BOM that this fixes. In Windows PowerShell 5.1, > writes UTF-16 LE (FF FE). That file fails with invalid UTF-8 both before and after this PR. The UTF-8 BOM comes from Out-File -Encoding utf8 or Set-Content -Encoding UTF8.
  2. The description says hashdict, world_index and classify_carve already read the index as utf-8-sig. At this head they open index.json as utf-8 (tools/hashdict.py:139, tools/world_index.py:551, tools/classify_carve.py:44). Open PRs hashdict: read a carve index.json saved with a UTF-8 BOM (EGEN-HASHDICT-INDEX-BOM) #6871, world_index: read a carve index.json saved with a UTF-8 BOM #6017 and classify_carve: read a carve index saved with a UTF-8 BOM (EGEN-CLASSIFY-INDEX-BOM, DeepSeek3) #5960 change them.

Overlap:

AI-assisted (Claude Code).

@evilclanker9000

Copy link
Copy Markdown
Contributor Author

This PR is approved but no longer merges cleanly with main: merging upstream/main conflicts in tools/shader_stage_manifest.py. Please merge main into the branch (no rebase) and resolve the conflict; the CI check should then go green on the new head.

AI-assisted.

@skorex

skorex commented Nov 23, 2026

Copy link
Copy Markdown

Duplicate of #5915

#5915 makes the same change and was opened earlier. Topic: shader_stage_manifest: carve index with UTF-8 BOM.

Suggest closing this PR in favour of #5915, and porting anything this one adds that #5915 lacks there.

@airp1ane

Copy link
Copy Markdown
Contributor

Tested dab31cf on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass.

Ran the test files this PR adds or changes, from a clean checkout of the PR head: test_shader_stage_manifest.py - all exit 0.

AI-assisted (Claude Code).

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