[PR #2069] [MERGED] fix(artifacts): compare package signatures without ASCII folding #5001

Closed
opened 2026-10-31 00:57:53 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2069
Author: @1052326311
Created: 10/12/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @morluto

Base: main ← Head: fix/package-magic-bytes


📝 Commits (1)

  • b8a4379 fix(artifacts): compare package signatures without ASCII folding

📊 Changes

3 files changed (+39 additions, -4 deletions)

View changed files

📝 src/application/BinaryTargetResolver.ts (+2 -2)
📝 src/artifacts/inventory/classify.ts (+2 -2)
📝 tests/boundary/filesystem/zipDetection.test.ts (+35 -0)

📄 Description

Summary

Reject high-bit aliases of PKG/DMG signatures at artifact inventory and binary-target admission. Node's Buffer.toString("ascii") clears bit 7: f8 61 72 21 decodes as xar!, and eb 6f 6c 79 as koly. These are not the format signatures but currently select the package routes.

Problem and expected behavior

A .pkg with the former four bytes is reported as PKG; a 512-byte .dmg with the latter at its trailer is reported as DMG. Classification must compare the observed bytes exactly. Found while inspecting the admission boundary; no separate issue exists.

Change and scope

Replace the four lossy string comparisons with exact buffer equality in the two existing admission paths. Keep their suffix, read-length, and trailer-location requirements. No package decoder or execution path is added.

Contract and boundary impact

  • Semantic owner and earliest changed stage: artifact format recognition in inventory and BinaryTargetResolver.
  • CLI and MCP/tool-catalog contract: malformed high-bit aliases stop selecting PKG/DMG; schemas unchanged.
  • Provider, bridge, target-format, or platform compatibility: exact valid signatures retain their existing classification; no bridge changes.
  • Evidence, artifact, provenance, or reconstruction contract: classification follows observed bytes, with no hash/provenance changes.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

Real filesystem fixtures cover valid signatures plus an independent bit-7 mutation of each signature byte through both classifyAndHashRoot and parseBinaryTarget. Base 3bdc8730 fails both new cases (12 existing pass); the fix passes all 14. Current upstream 4573e8cf changes neither owner.

This validates static admission, not complete XAR/UDIF validity or native package mounting. No real Hopper/Ghidra/browser verification is applicable.

  • 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

Node 24.18.0 / npm 11.16.0, macOS arm64:

  • npm run test:focused -- tests/boundary/filesystem/zipDetection.test.ts — 14 passed; includes build preparation.
  • npm run check — passed, lint warnings and zero errors.
  • npm run docs:check — passed.
  • Pre-push check:fast and git diff --check — passed.

Compatibility, safety, and release

No breaking API, migration, package metadata, or authority changes. Invalid files may now yield the ordinary file classification or a BinaryTargetError instead of a false package format. Full suite and native mounting were not run.

Review checklist

  • Concrete bug, focused conventional title, no separate issue as explained above.
  • Regression covers both affected consumers and valid controls.
  • Metadata checks pass; no generated files committed.
  • Final diff checked for secrets, unrelated changes, and unsupported claims.

AI-assisted with Codex.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/2069 **Author:** [@1052326311](https://github.com/1052326311) **Created:** 10/12/2026 **Status:** ✅ Merged **Merged:** 10/12/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/package-magic-bytes` --- ### 📝 Commits (1) - [`b8a4379`](https://github.com/morluto/rea/commit/b8a4379f4f466621d011afa06fc9b61ff771879f) fix(artifacts): compare package signatures without ASCII folding ### 📊 Changes **3 files changed** (+39 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/application/BinaryTargetResolver.ts` (+2 -2) 📝 `src/artifacts/inventory/classify.ts` (+2 -2) 📝 `tests/boundary/filesystem/zipDetection.test.ts` (+35 -0) </details> ### 📄 Description ## Summary Reject high-bit aliases of PKG/DMG signatures at artifact inventory and binary-target admission. Node's `Buffer.toString("ascii")` clears bit 7: `f8 61 72 21` decodes as `xar!`, and `eb 6f 6c 79` as `koly`. These are not the format signatures but currently select the package routes. ## Problem and expected behavior A `.pkg` with the former four bytes is reported as PKG; a 512-byte `.dmg` with the latter at its trailer is reported as DMG. Classification must compare the observed bytes exactly. Found while inspecting the admission boundary; no separate issue exists. ## Change and scope Replace the four lossy string comparisons with exact buffer equality in the two existing admission paths. Keep their suffix, read-length, and trailer-location requirements. No package decoder or execution path is added. ## Contract and boundary impact - Semantic owner and earliest changed stage: artifact format recognition in inventory and `BinaryTargetResolver`. - CLI and MCP/tool-catalog contract: malformed high-bit aliases stop selecting PKG/DMG; schemas unchanged. - Provider, bridge, target-format, or platform compatibility: exact valid signatures retain their existing classification; no bridge changes. - Evidence, artifact, provenance, or reconstruction contract: classification follows observed bytes, with no hash/provenance changes. - Process execution, authorization, cleanup, or containment impact: none. - Generated metadata, package, or installation impact: none. ## Evidence and regression coverage Real filesystem fixtures cover valid signatures plus an independent bit-7 mutation of each signature byte through both `classifyAndHashRoot` and `parseBinaryTarget`. Base `3bdc8730` fails both new cases (12 existing pass); the fix passes all 14. Current upstream `4573e8cf` changes neither owner. This validates static admission, not complete XAR/UDIF validity or native package mounting. No real Hopper/Ghidra/browser verification is applicable. - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed Node 24.18.0 / npm 11.16.0, macOS arm64: - `npm run test:focused -- tests/boundary/filesystem/zipDetection.test.ts` — 14 passed; includes build preparation. - `npm run check` — passed, lint warnings and zero errors. - `npm run docs:check` — passed. - Pre-push `check:fast` and `git diff --check` — passed. ## Compatibility, safety, and release No breaking API, migration, package metadata, or authority changes. Invalid files may now yield the ordinary file classification or a `BinaryTargetError` instead of a false package format. Full suite and native mounting were not run. ## Review checklist - [x] Concrete bug, focused conventional title, no separate issue as explained above. - [x] Regression covers both affected consumers and valid controls. - [x] Metadata checks pass; no generated files committed. - [x] Final diff checked for secrets, unrelated changes, and unsupported claims. AI-assisted with Codex. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 00:57:53 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5001
No description provided.