Skip to content

fix(artifacts): keep case-distinct archive names in inventory - #1480

Merged
morluto merged 1 commit into
mainfrom
cursor/apk-path-identity-07c3
Oct 10, 2026
Merged

morluto merged 1 commit into
mainfrom
cursor/apk-path-identity-07c3

Conversation

@morluto

@morluto morluto commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #1470. Shrunk release APKs can contain ZIP names that differ only in case, such as res/2F.xml and res/2f.xml. Inventory treated that as an unsafe path, so inspect-artifact failed and project-android-application-graph had no evidence. Both names now stay in the inventory, with a limitation that a case-insensitive destination cannot store both.

Problem and expected behavior

ArtifactPathRegistry folded every ZIP segment with English case folding during inventory. ZIP names are case-sensitive, and Android resource shrinking uses both cases. The failure was reported as a path the analyst should correct, and --integrity-policy record-and-continue did not apply.

Inventory should keep both logical names. Extraction should fail only when the destination directory cannot keep both spellings.

Change and scope

Logical registration is exact spelling. Exact duplicates and same-spelling file/directory prefixes still fail. After the scan, each affected occurrence and the inventory record that English (en-US) Unicode case folding collides those names. That note is not a filesystem observation and is not an integrity contradiction.

SafeOutputTree is the materialization boundary. It still refuses a second write of one logical path. If creating a segment fails and the parent listing already holds another English-case spelling, extraction names both paths, points back at the inventory, and rolls the tree back. Case-sensitive volumes write both files.

The Android projection no longer compares component formats with android-manifest, android-resources, dex, or jvm-class. Inventory never emits those labels. Classification stays on the path rules. Every projection states that ZIP inventory cannot see the APK Signing Block, so an empty signing array does not mean unsigned, and that a bridge basis comes from the native path and is repeated for every managed component.

.aab is no longer classified as apk. An app bundle with ZIP magic is a zip. JADX and the application graph already require an APK.

Not included: an APK Signing Block parser, split-APK sets, a JADX-to-graph join, or DEX/binary-XML magic detection.

Contract and boundary impact

  • Semantic owner and earliest changed stage: logical archive identity in ArtifactPathRegistry during inventory; destination collision in SafeOutputTree during extraction.
  • CLI and MCP/tool-catalog contract: no schema change. Path failures still use artifact_operation_failed / path. Unsafe paths still tell the analyst to correct the artifact. A destination case collision returns the spelling pair and says the inventory retains both names.
  • Provider, bridge, target-format, or platform compatibility: .aab resolves as zip instead of apk.
  • Evidence, artifact, provenance, or reconstruction contract: case-distinct members are inventoried. Inventory and occurrence limitations record the English case-folding collision. Android projection limitations add the signing-block and bridge-basis notes. Coverage remains inventory completeness.
  • Process execution, authorization, cleanup, or containment impact: none. Extraction rollback is unchanged.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: archive safety (logical names, destination-listing message, extraction of Main.js and main.js), path-failure presentation, and an APK with res/2F.xml and res/2f.xml that inventories and projects.
  • Base reproduction or other evidence: the registry previously rejected a.js after A.js. That case now inventories both entries.
  • User-visible CLI/MCP output (if applicable): inspect-artifact succeeds for case-distinct ZIP names and includes the case-folding limitation. Extraction on a case-insensitive volume fails with Destination filesystem cannot store both <path> and <other>; inventory retains both logical names.
  • Remaining proof gaps: Windows and macOS refusal of a case-insensitive destination was not executed. The collision message is tested as a pure function of the requested path and a directory listing. Linux CI covers writing both spellings.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- tests/composition/android/application.test.ts — 6 passed
  • npm run test:focused -- tests/boundary/providers/native/artifactProvider.archiveSafety.test.ts tests/boundary/providers/native/artifactProvider.failureDetail.test.ts — 8 passed
  • pre-push npm run check:fast — typecheck and lint passed

Real JADX was not required. The graph change consumes inventory evidence only.

Compatibility, safety, and release

  • Breaking changes or migration steps: none for a supported contract. An .aab path that was previously labeled apk is now zip, so Android package tools and the application graph refuse it as a non-APK.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable. Case-insensitive extraction refusal was not run on Windows or macOS.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: extraction still uses an exclusive create and rolls back on failure. Case folding is no longer a reason to reject a logical archive name.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.
Open in Web Open in Cursor 

ZIP member names are case-sensitive. Inventory was folding them with a
filesystem case rule, so shrunk APKs never became evidence for the Android
application graph. Logical registration now keeps both spellings and records
an English Unicode case-folding limitation. Extraction fails only when the
destination directory already holds the other spelling.
@morluto
morluto marked this pull request as ready for review October 10, 2026 07:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T07:25:22.525186Z 312263a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@morluto
morluto merged commit 1f07756 into main Oct 10, 2026
14 checks passed
@morluto
morluto deleted the cursor/apk-path-identity-07c3 branch October 10, 2026 07:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 312263a215

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +201 to +203
groups.flatMap((candidate, candidateIndex) =>
candidateIndex === index ? [] : candidate,
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid expanding case-collision subtrees quadratically

When an archive contains large case-variant directory trees such as Foo/{a1...aN} and foo/{b1...bN}, this cross-products every terminal beneath one spelling with every terminal beneath the other. The resulting sets and per-occurrence others.join(...) strings require O(N²) memory, so a modest untrusted ZIP can exhaust the process before inventory is returned. Record the collision at the affected directory segment, or retain a bounded representative rather than materializing every descendant pair.

AGENTS.md reference: AGENTS.md:L42-L42

Useful? React with 👍 / 👎.

Comment on lines +183 to +186
for (const spellings of node.spellingsByFold.values())
if (spellings.length > 1) noteFoldedSpellings(node, spellings, collisions);
for (const child of node.bySpelling.values())
recordCaseCollisions(child, collisions);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Walk the path trie without recursive stack growth

For a ZIP entry with thousands of short path components, recordCaseCollisions recurses once per component even when there are no collisions. Such a name can fit within ZIP's filename field while exceeding Node's call-stack depth, causing an otherwise accepted inventory to fail with a RangeError; use an iterative traversal or enforce a documented format-derived depth limit.

AGENTS.md reference: AGENTS.md:L42-L42

Useful? React with 👍 / 👎.

Comment on lines +167 to +169
expect(extracted.ok).toBe(true);
expect(await readFile(join(output, "Main.js"), "utf8")).toBe("upper");
expect(await readFile(join(output, "main.js"), "utf8")).toBe("lower");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Make the extraction assertion filesystem-aware

On the checked windows-curated job (.github/workflows/ci.yml:414-420), this test runs on the default case-insensitive Windows filesystem. Creating main.js after Main.js therefore makes SafeOutputTree.write report the destination case collision and roll back, so extracted.ok is false and this required CI lane fails. Keep the inventory assertions cross-platform, but only expect successful extraction after detecting a case-sensitive destination; otherwise assert the intended collision failure.

Useful? React with 👍 / 👎.

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The fix works. Coffee 2.27 now loads with both res/2f.xml and res/2F.xml kept, and the Android graph runs on it. Five more F-Droid apps failed the same way before the merge, and all five load now.

I tested the merge 1f0775684 against its parent 7296f2b5b. The squash diff matches the PR diff byte for byte.

Coffee 2.27 (Apache-2.0), CLI

Check Node 22 Node 24 Node 26
inspect-artifact on 7296f2b5b exit 1, path collision exit 1, path collision exit 1, path collision
inspect-artifact on 1f0775684 exit 0 exit 0 exit 0
Same, with record-and-continue exit 0 exit 0 exit 0
project-android-application-graph exit 0 exit 0 exit 0
extract-artifact to tmpfs 840 of 840 files 840 of 840 files 840 of 840 files
The PR's 3 test files 14 passed 14 passed 14 passed

A fix to my count in #1470: I said 39 pairs. It is 39 groups, with 79 names. One group is a triple: res/BT.xml, res/bT.xml and res/bt.xml. Each of the three names lists the other two.

MCP over stdio (Node 24)

Tool 7296f2b5b 1f0775684
open_binary ok ok
inspect_artifact error, path collision ok, same inventory as the CLI
project_android_application_graph no input to give it ok, same as the CLI
extract_artifact error, path collision ok, 840 of 840 files

inspect_artifact takes no path. It works on the target from open_binary.

More F-Droid apps (Node 24)

Each APK's SHA-256 matches F-Droid's signed index.

App Zip entries Case groups 7296f2b5b 1f0775684 Graph
Stay Put 0.8.11 (MIT) 788 32 exit 1 exit 0 exit 0
NFC Quick Settings 1.5.4-pre (GPL-3.0-or-later) 717 29 exit 1 exit 0 exit 0
MinCal Widget 2.20.0 (BSD-3-Clause) 428 9 exit 1 exit 0 exit 0
Bubble 3.5 (GPL-3.0-or-later) 459 15 exit 1 exit 0 exit 0
Intent Intercept 4.1.0 (Apache-2.0) 498 13 exit 1 exit 0 exit 0
WordleSolver 1.13 (GPL-3.0-only) 48 0 exit 0 exit 0 exit 0 both

WordleSolver has no case pairs. Its inventory is the same on both commits. Its graph only gains the two new notes.

Stay Put shows why the signing note matters. It has only a newer-style signature. That signature lives in a block that zip readers skip. So the graph lists no signing files, yet the APK is signed. The new note says just that.

I also renamed a copy of the WordleSolver APK to .aab. It is a renamed APK, not a real app bundle. On 1f0775684 it reads as zip, and the graph and inspect-android-package refuse it.

I also ran the new tests against the 7296f2b5b source, and 8 of 14 failed. Three of those hit the old path error. Two fail because a new helper is missing there.

Not run

  • Extraction to a disk that ignores case. Mounting one here needs root. So the new "cannot store both" error is untested.
  • macOS or Windows.
  • A real .aab app bundle.
  • npm run check:fast.
  • Case pairs outside plain ASCII. Every pair I found was ASCII.
  • Split APKs.

Thanks, morluto, for the quick fix and the clear signing note.

Edit: The sources for WordleSolver do not agree on its licence. F-Droid says GPL-3.0-only, the repo's LICENSE file says Apache-2.0, and the source headers say GPL-3.0-or-later.

Coffee details

The inventory output on 1f0775684 is the same on all three Node versions.

  • Inventory: all 840 names match unzip -l. res/2F.xml is 724 bytes and res/2f.xml is 1,916 bytes. REA marks every entry hash as verified.
  • Case note: the inventory has the new English case-folding note. So does each of the 79 names involved.
  • Graph: one manifest, one resources.arsc, one classes.dex and three signing files. Both new notes are there, on the signing block and the bridge basis.
  • Extraction: the extracted files match the APK byte for byte. Both spellings land on disk.
  • Other Android commands: I reran the five from [Bug] inspect-artifact rejects a valid APK whose entries differ only in case #1470. That is package, class search, class, method and references. Each gives the same result on 7296f2b5b and 1f0775684 on Node 24. Each also matches my 6.3.0 run in [Bug] inspect-artifact rejects a valid APK whose entries differ only in case #1470.
Commands
rea inspect-artifact coffee.apk --format json
rea inspect-artifact coffee.apk --integrity-policy record-and-continue --format json
# graph input: {"inventory_evidence":[<normalized_result.substeps[0].evidence>]}
rea project-android-application-graph graph-in.json --format json
rea extract-artifact coffee.apk --format json
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

MCP order: open_binary {path}, inspect_artifact {}, inspect_artifact {integrity_policy}, project_android_application_graph, extract_artifact {}, close_binary {}.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head / base: 1f0775684 / 7296f2b5b
  • Extraction: on tmpfs, where case counts
  • REA: built from source at head and base, with npm ci and npm run build on Node 24
  • Android: JADX via REA_JADX_MCP_JAR, on Temurin JDK 21 (GPL-2.0-only WITH Classpath-exception-2.0)

🤖 Generated with Claude Code (Opus 5.5) 🦊

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…o#1480)

ZIP member names are case-sensitive. Inventory was folding them with a
filesystem case rule, so shrunk APKs never became evidence for the Android
application graph. Logical registration now keeps both spellings and records
an English Unicode case-folding limitation. Extraction fails only when the
destination directory already holds the other spelling.

Co-authored-by: Cursor Agent <[email protected]>
N0zoM1z0 added a commit that referenced this pull request Oct 11, 2026
Reject duplicate ZIP filenames before an emitted entry source lookup can be overwritten. Preserve valid repeated enumeration, case-distinct paths and typed inventory path failures.

Closes #1725. Related: #1480.
@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.

[Bug] inspect-artifact rejects a valid APK whose entries differ only in case

3 participants