Skip to content

fix: order remaining outputs independently of host locale - #1867

Merged
morluto merged 2 commits into
morluto:mainfrom
dollarsmoney:fix/locale-independent-ordering
Oct 11, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
dollarsmoney:fix/locale-independent-ordering

Conversation

@dollarsmoney

Copy link
Copy Markdown
Contributor

Summary

String.prototype.localeCompare() without a pinned collation follows the host's ICU default locale, which comes from LANG/LC_ALL. The same input can therefore be ordered differently on different machines. 614fb76 ("fix(evidence): order canonical projections independently of locale") moved the canonical domain projections to compareUnicodeCodePoints. Forty-two localeCompare calls in 30 provider, application, catalog and setup files still used locale collation. This PR orders all of them by Unicode code point, so no localeCompare remains in non-test source.

No linked issue: I found this while reading the code, as a direct follow-up to 614fb76.

Problem and expected behavior

Smallest trigger, on unmodified main: inventoryFirmwareOutput sorts extracted firmware paths with localeCompare.

LC_ALL=en_US.UTF-8   a.bin ä.bin B.bin z.bin
LC_ALL=sv_SE.UTF-8   a.bin B.bin z.bin ä.bin
code point           B.bin a.bin z.bin ä.bin

The violated invariant: evidence and listings derived from the same target should not depend on the analyst's locale. The same kind of drift affects Mach-O symbol lists (_main / _Zeta / Zeta interleave differently from code-point order), and any sorted set that later feeds a digest or comparison.

Change and scope

Every remaining non-test a.localeCompare(b) becomes compareUnicodeCodePoints(a, b), the existing owner in src/domain/unicodeCodePointOrder.ts. I applied it with a parser-based rewrite and reviewed the result by hand:

  • Evidence and provider output: Mach-O symbols (NativeMachoInspection), firmware extraction paths (FirmwareFiles), ASAR entries (AsarArtifactReader, previously pinned to "en" collation, which still varies by ICU version and is not code-point order), and evidence ID sets (registerInvestigationTools/helpers).
  • Browser and Electron inventories: page capture scripts, capture documents, targets, workers, scripts, resources and WebMCP tools.
  • Reconstruction obligations, the evidence ledger's unknowns, and capability, provider and session-status listings.
  • Catalog identity (catalogIdentity.ts), client registration and setup environment details, process ownership diagnostics, and the Ghidra transport's exact-key check.

Not included: test files and PeResources.fixture.ts, which are not shipped output. Nothing here was human-facing collation; every site orders machine keys such as IDs, names, paths and environment variable names.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the existing compareUnicodeCodePoints owner; each producer's final ordering step.
  • CLI and MCP/tool-catalog contract: no schema change. The catalog identity digest is unchanged, because the current 172 tool names and 6 prompt names order identically under both comparators (checked with dist/contracts).
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: ordering is now host-independent. Where locale collation and code-point order differ (mixed case, _, digits, non-ASCII), listed items may appear in a different order than before. Set membership is unchanged.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/firmware/firmwareReportFiles.test.ts now inventories a.bin, z.bin, ä.bin, B.bin and Lib/x.bin on the real filesystem through inventoryFirmwareOutput and asserts code-point order.
  • Base reproduction: with only src/firmware/FirmwareFiles.ts reverted to main, the new test fails (1 failed | 5 passed). With the change it passes. The locale table above was produced with node -e under each LC_ALL.
  • User-visible CLI/MCP output: ordering only, as described above.
  • Remaining proof gaps: only firmware has a dedicated regression test. The other sites are the same one-line comparator substitution and are covered by their existing tests.

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

macOS 15 (Darwin 24.3.0, arm64), Node 26.9.0:

  • npm run check:fast: typecheck and lint passed; it also passed as the pre-push hook after rebasing onto 1f531fc2.
  • npm run check:changed: 83 test files, 854 passed, 4 skipped.
  • npm run test:focused -- <all 176 files under tests/boundary/{firmware,filesystem,browser,process}>:
    • 7 Interface Builder / NIB tests fail because ibtool requires full Xcode and this host has only the Command Line Tools. The same 7 fail on unmodified main in a separate worktree.
    • keyedArchiveNativeIntegers (30 s timeout) and processFilesystemCoverageAdapters (process-ownership read) failed once under the full parallel run. Both then passed twice when rerun on this branch.
    • Everything else passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Item sets are unchanged; only locale-dependent ordering becomes code-point ordering.
  • Real Hopper/Ghidra, browser, or OS coverage: no real providers run. macOS only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: comparator substitution only.

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.

String.prototype.localeCompare without a pinned collation follows the
host's ICU default locale, so the same input could be ordered differently
on different machines. 614fb76 moved canonical domain projections to
compareUnicodeCodePoints; provider, application, catalog, and setup
orderings still used locale collation.

Order every remaining source site by Unicode code point, including Mach-O
symbols, firmware extraction paths, ASAR entries (previously pinned to
"en" collation), evidence ID sets, browser and Electron target, script,
and resource inventories, reconstruction obligations, capability and
provider listings, and setup environment details.

The current tool and prompt catalog names order identically under both
comparators, so the catalog identity digest is unchanged.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 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-11T15:00:20.006167Z de51642 New commits
ℹ️ 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.

@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: e16dfc71d9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/artifacts/AsarArtifactReader.ts Outdated
Comment on lines +86 to +87
paths = listPackage(snapshotPath, { isPack: false }).sort((left, right) =>
left.localeCompare(right, "en"),
compareUnicodeCodePoints(left, right),

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 Sort ASAR entries by their portable path

On Windows, listPackage supplies host-spelled paths containing \, so applying code-point order to listed before toArtifactPath makes this result platform-dependent: an archive with a/b and a0 orders the nested entry first on POSIX (/ < 0) but the flat file first on Windows (0 < \), even though both are later exposed with /. Retain the raw spelling for statFile/adapterKey, but normalize a separate sort key before sorting.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in de51642. orderAsarListing now pairs each host-spelled listing with its portable archive path once and sorts by that path. The host spelling is kept for @electron/asar calls and adapter keys. src/artifacts/AsarArtifactReader.test.ts covers your a/b vs a0 case with both / and \ separators; both orders are now a, a/b, a0. The previous "en" collation had the same separator dependence, so this also closes a gap that predates the PR.

@electron/asar lists host-spelled paths, so code-point order over the raw
spelling still differed by host: "a\b" sorts after "a0" on Windows while
"a/b" sorts before it on POSIX. Pair each listing with its portable
archive path once, order by that path, and keep the host spelling for
@electron/asar calls and adapter keys.
@morluto
morluto merged commit e4ac7bb into morluto:main Oct 11, 2026
31 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
3 tasks done
@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Welcome, @dollarsmoney! Replacing the remaining locale-dependent comparisons with REA’s code-point comparator makes machine-key ordering consistent across host locales. The regressions also cover firmware output and portable archive-path ordering. Thanks for applying it across the project.

@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@dollarsmoney
dollarsmoney deleted the fix/locale-independent-ordering branch October 15, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants