Skip to content

bvh_match: read manifest JSON with utf-8-sig - #6366

Open
BBareth wants to merge 1 commit into
ItsNotRexed:mainfrom
BBareth:fix/bvh-match-utf8-bom
Open

BBareth wants to merge 1 commit into
ItsNotRexed:mainfrom
BBareth:fix/bvh-match-utf8-bom

Conversation

@BBareth

@BBareth BBareth commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #6214 (comment)

What and why

tools/bvh_match.py previously opened the manifest JSON with encoding="utf-8", so a manifest saved with a UTF-8 BOM failed with error: Unexpected UTF-8 BOM ... and exit code 2. Reading with encoding="utf-8-sig" accepts both plain UTF-8 and UTF-8 with BOM, and tests/test_bvh_match.py adds positive and malformed-JSON regression cases.

Tested

  • Environment: macOS (arm64), Python 3.9.6, CPU only, no game data.
  • python3 -I -m compileall -q tools/bvh_match.py tests/test_bvh_match.py -> exit 0
  • python3 -I tests/test_bvh_match.py -v -> 35/35 passed
  • python3 -I tests/test_text_write_line_endings.py -> 3/3 passed

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

@dcastell1

Copy link
Copy Markdown
Contributor

Code read + CPU tests, a6f4bf9: pass (tests/test_bvh_match.py → 35 passed, 11 subtests).

@morodirule

Copy link
Copy Markdown

Tested a6f4bf9 on Arch Linux, Python 3.14.10, CPU only: pass, first Linux check on this head. tests/test_bvh_match.py 35/35 OK plus bvh_rehydrate 16, bvh_groups 13, bvh_index 40, geometry_check 7, packing_check 30, tri_probe 15 OK. Negative control: merge-base tool fails exactly the new BOM test; restored, 35/35 green. No game files. AI-assisted.

@AsgerCode

Copy link
Copy Markdown

Tested a6f4bf9 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

The earlier comments covered the tests and the negative control on the PR head. This adds the merge with current main, the other reader of the same manifest, and the overlap with #4310.

What I ran:

Who writes the manifest and who reads it:

  • rpf9dump models writes manifest.json with Utf8JsonWriter on a FileStream (tools/rpf9dump/Program.cs:240-241 on main). That writes no BOM. So a BOM comes only from a user who saves the file again, for example with Windows PowerShell 5.1 Set-Content -Encoding utf8.
  • bvh_match.py reads the manifest in one place (the line this PR changes). The only other reader is tools/bvh_slot_check.py:149, json.loads(manifest.read_bytes()). That already accepts a UTF-8 BOM (json.detect_encoding returns utf-8-sig). After this PR the two readers agree.
  • tools: fix BOM-prefixed JSON inputs in 10 utilities (batch 01) #6779 (BOM batch 01) did not include bvh_match.py. Current main still has encoding="utf-8" at line 323.

By hand, with the synthetic BLAS, OBJ and one-item manifest from tests/test_bvh_match.py:

manifest bytes main 867d922 PR on main
plain UTF-8 exit 0, 1 consistent exit 0, 1 consistent
UTF-8 BOM exit 2, Unexpected UTF-8 BOM exit 0, 1 consistent
BOM, CRLF, indented exit 2 exit 0, 1 consistent
two BOMs exit 2 exit 2, Unexpected UTF-8 BOM
BOM only exit 2 exit 2, Expecting value
BOM + {not valid json exit 2 exit 2, Expecting property name ...
UTF-16 LE with BOM exit 2, 'utf-8' codec can't decode byte 0xff same

No case gave a traceback.

Overlap:

Nits, none blocking:

  1. A UTF-16 manifest (the default of Out-File and > in Windows PowerShell 5.1) is still refused, with a clean error. bvh_slot_check.py accepts it, because json.loads on bytes detects UTF-16. If you want the two readers to agree fully, json.loads(f.read()) on a file opened with "rb" does that. This is outside the scope of the PR.

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.

4 participants