Skip to content

fix(artifacts): record each case collision once at its diverging segment - #1505

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
fix/case-collision-linear
Oct 10, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
fix/case-collision-linear

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

This addresses the two ArtifactPaths.ts review findings left open on #1480. (The third finding, about the Windows extraction test, was fixed in b12d0c6.)

Quadratic growth. noteFoldedSpellings collected every terminal under each case spelling and gave each one a set of all terminals under the other spellings. Each occurrence then received one limitation joining those paths. With Foo/ and foo/ holding N files each, that is 2N occurrences each listing N paths.

Repro, a ZIP with Foo/a{i}.txt and foo/b{i}.txt, using rea inspect-artifact x.zip --format json:

N per spelling main: bytes / max RSS this branch: bytes / max RSS
500 7,903,661 / 392 MB 1,038,661 / 379 MB
1,000 29,802,665 / 554 MB —
2,000 119,604,665 / 943 MB 4,144,665 / 494 MB

A somewhat larger untrusted ZIP would exhaust the process before inventory returns.

Recursion. recordCaseCollisions and terminalsUnder recursed once per path component. A ZIP name with about 30,000 one-letter components still fits the 65,535-byte name field, and it threw RangeError: Maximum call stack size exceeded.

Change

  • A collision is recorded once, at the segment where the spellings diverge. A linked chain shares it with every path in that subtree. The trie is walked with an explicit stack.

  • Each affected occurrence names the colliding prefix and the first other spelling in code-point order, plus a count when there are more spellings:

    • same file, two spellings (unchanged text): Logical path Main.js collides under English (en-US) Unicode case folding with main.js; …
    • a path under a colliding directory: Logical path res/foo/b.txt is under res/foo, which collides under English (en-US) Unicode case folding with res/Foo; …
    • three or more spellings: … with A.txt and 1 other spelling; …

    Every spelling is still its own occurrence with its own limitation, so the full set stays in the result. The inventory-level limitation and extraction behavior are unchanged.

Verification

  • New src/artifacts/ArtifactPaths.test.ts covers the file message, a directory collision on descendants, the count form, a 2×5,000 subtree with one bounded limitation per occurrence, and a 30,000-component name. On main four of the five fail: the stack test with RangeError, and the subtree test runs 4.2 s with N-entry lists.
  • npm run test:focused -- tests/boundary/providers/native/artifactProvider.archiveSafety.test.ts tests/boundary/providers/native/artifactProvider.failureDetail.test.ts tests/composition/android/application.test.ts passes (14 tests).
  • npm run check:fast and npm run docs:check pass.
  • No real Hopper or Ghidra verification was needed.

🤖 Generated with Claude Code

Inventory paired every path under one case spelling with every path under
each other spelling and listed all of them on each occurrence. An archive
with Foo/ and foo/ subtrees of N files each produced N-entry lists on 2N
occurrences: 4,000 such ZIP members yielded a 120 MB inspect_artifact
result and close to 1 GB of memory. The trie walks also recursed once per
path component, so a ZIP name with tens of thousands of components threw
RangeError.

A collision is now recorded at the segment where spellings diverge and
shared down that subtree by an iterative walk. Each occurrence names the
colliding prefix and the first other spelling, plus a count of further
spellings, each of which is its own occurrence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 983b070 into main Oct 10, 2026
20 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/case-collision-linear branch October 10, 2026 08:16
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…ent (morluto#1505)

Inventory paired every path under one case spelling with every path under
each other spelling and listed all of them on each occurrence. An archive
with Foo/ and foo/ subtrees of N files each produced N-entry lists on 2N
occurrences: 4,000 such ZIP members yielded a 120 MB inspect_artifact
result and close to 1 GB of memory. The trie walks also recursed once per
path component, so a ZIP name with tens of thousands of components threw
RangeError.

A collision is now recorded at the segment where spellings diverge and
shared down that subtree by an iterative walk. Each occurrence names the
colliding prefix and the first other spelling, plus a count of further
spellings, each of which is its own occurrence.
@morluto morluto added bug Something isn't working area: evidence Evidence, artifacts, and reconstruction labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants