Skip to content

hashdict: a string longer than 201 characters is not cut into fragments - #1121

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
nightmoon1996:fix/hashdict-long-strings
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
nightmoon1996:fix/hashdict-long-strings

Conversation

@nightmoon1996

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1006 (comment) (new BUILD item)

What and why

tools/hashdict.py harvests names with [A-Za-z_][A-Za-z0-9_./:\-]{2,200}. A run longer than 201 characters ends the match there, and the next match starts in the middle of the same run. So harvest added a truncated 201-character prefix and a fragment as if they were names, and the path component across the cut was never added.

Example (synthetic): a 230-character platform:/levels/.../props_lev_des_building_name.ytd. Before, props_lev_des_building_name was missing and ops_lev_des_building_name, ops_lev_des_building_name.ytd and a prefix ending in /pr were in the dictionary. The dictionary keeps the alphabetically first name on a hash collision, so such fragments can also displace a real name.

Now the whole run is matched and split into its parts as before. A run, or a part, longer than 201 characters (MAX_NAME_LEN) is not added as a name; the old pattern could never produce a longer entry, so the dictionary's ceiling is the same. A long path contributes all its components; a long token with no separator contributes nothing. The parts are found one at a time, so a run of megabytes does not build a list of all of them.

For input with no run over 201 characters the harvested set is identical to before.

Tested

CPU only, synthetic data, no game files, no GPU. Windows 11, Python 3.14; also Python 3.11 and Linux (WSL, Python 3.10).

  • python -I tests/test_hashdict.py: 25 tests pass (3 new: the 230-character path, a separator-free token over the cap, a run of exactly the cap).
  • With main's pattern the first two fail: the path test with 'props_lev_des_building_name' not found, the token test because fragments are added. The third passes on both; it pins the boundary.
  • Old against new harvest on random blobs with no run over 201 characters (noise, embedded names of 199, 200 and 201 characters, --min from -1 to 8): identical sets over 1,200 harvests; a second, independent run of 30,000 inputs also matched.
  • Speed is about the same: a 50 MB run of one character took 0.25 s (0.49 s before). A 20 MB run of abc/abc/... peaks at 21 MB under tracemalloc, which is the run itself.
  • python -m compileall -q make_game.py tools tests is clean. Not run on a real carve folder.

AI-assisted (Claude Code).

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. (not a translator change)

🤖 Generated with Claude Code

The harvest pattern ended a match after 201 characters and the next match
started in the middle of the same run, so a truncated prefix and a fragment
were added as names and the path component across the cut was lost. The
whole run is matched now and split into its parts as before; a run or a
part longer than 201 characters is not added as a name, which keeps the
longest entry the dictionary could ever hold. Parts are found one at a time,
so a very long run does not build a list of all of them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@kapitche

Copy link
Copy Markdown
Contributor

Tested 9f95b08 on Linux (WSL2 Ubuntu), Python 3.12, CPU only: pass

  • pytest tests/test_hashdict.py: 25 passed, 8 subtests. With tools/hashdict.py from main, 3 fail (the over-cap token, the straddling component, and exactly-the-cap).
  • Equivalence below the cap: on 3,000 random byte strings of up to 400 bytes, each with minlen 0/1/3/4 (12,000 comparisons), old and new harvest return the same set.
  • Above the cap, a 300- or 5,000-character component now adds only its short parts, where it used to add 201-character fragments.
  • Speed: a single 30 MB token takes 0.08 s and adds nothing, and a 30 MB ab/ run takes 0.96 s.
  • Conflicts: BUILD: validate archive index files in hashdict #1048 is closed. runtime: thunk deduplication, XGameRuntime shims, PE loader long paths, and drive-root packaging #1064 no longer touches tools/, and merging it into this branch is clean.

@nightmoon1996

Copy link
Copy Markdown
Contributor Author

The red check job is not from this change: it stops at tests/test_carve_all_paths.py (trailing-separator subtest, carving me\common.rpf), which fails the same way on main at c63773d because the runner's temp path is an 8.3 short name. #1123 fixes it. The job stops at the first failing file, so this PR's own test file, which sorts after it, has not run in CI yet; it passes locally (see Tested). I will rebase once #1123 is in so it runs. AI-assisted.

@lucastayaralvarenga-ui lucastayaralvarenga-ui left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at 9f95b08. Windows / CPython 3.14: all 25 hashdict tests passed. The boundary regression preserves the path component crossing the old 201-byte cut, and the existing delimiter and minimum-length cases still pass. Long runs are matched as a whole before the per-name length cap is applied.

AI-assisted review. No game data.

@ItsNotRexed
ItsNotRexed merged commit 9ba1dd0 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
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