[PR #1784] [MERGED] fix(apple): validate build-version tool records within cmdsize #4814

Closed
opened 2026-10-31 00:55:19 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/1784
Author: @N0zoM1z0
Created: 10/11/2026
Status: ✅ Merged
Merged: 10/11/2026
Merged by: @N0zoM1z0

Base: main ← Head: fix/1775-macho-build-version-tools


📝 Commits (1)

  • 6c386d3 fix(apple): validate build-version tool records within cmdsize

📊 Changes

2 files changed (+73 additions, -1 deletions)

View changed files

📝 src/artifacts/apple/MachoLoadCommandReader.ts (+8 -1)
📝 tests/boundary/cli/dylibResolutionCli.test.ts (+65 -0)

📄 Description

Summary

Report malformed Mach-O LC_BUILD_VERSION commands when their declared tool records do not fit inside cmdsize. Fixes #1775.

Problem and expected behavior

A 24-byte command with ntools=1 previously produced parsed platform evidence despite having no tool record. The reader must validate the command's complete structure before accepting its platform.

Change and scope

Compare the declared count with the current command body's available 8-byte records, after checking its 24-byte header. This performs no count-driven allocation or iteration. Extra command padding remains accepted; unrelated load-command policies are unchanged.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Mach-O load-command decoding in MachoLoadCommandReader.
  • CLI and MCP/tool-catalog contract: no schema change; trace-dylib-resolution now reports these images as malformed.
  • Provider, bridge, target-format, or platform compatibility: offline Mach-O bytes; valid commands and unknown raw platform values remain supported.
  • Evidence, artifact, provenance, or reconstruction contract: preserve file identity and the parse failure; malformed images have no accepted slices and appear in partial coverage.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata, package, or installation impact: none; no generated outputs committed.

Evidence and regression coverage

  • Tests added or updated: one compiled CLI scenario covers valid zero/one records, unknown platform, missing one/two records, maximum u32 count, and a truncated header. A sibling command and image trailer cannot satisfy a missing record.

  • Base reproduction: the added CLI test failed against unchanged production at 0bdc7a40a: expected malformed, received parsed; nine existing CLI tests passed.

  • User-visible output: affected images expose parse_status: "malformed", a reason naming LC_BUILD_VERSION, empty slices, and partial coverage. The CLI can still exit 0 while preserving those failures.

  • Remaining proof gaps: Linux synthetic file workflows; no actual dyld execution or native macOS provider validation.

  • 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:focused -- src/artifacts/apple/MachoLoadCommandReader.test.ts tests/boundary/cli/dylibResolutionCli.test.ts — reader 24/24 and new CLI regression passed; one pre-existing CLI scenario hit its 30-second timeout.
  • npm run test:focused -- tests/boundary/cli/dylibResolutionCli.test.ts — rerun passed 10/10 without changing timeouts.
  • npm run check — typecheck, lint/module boundaries, formatting, Knip, metadata and architecture guards passed after moving the new test outside the existing describe block to respect its line limit.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; reject malformed input rather than changing valid calls.
  • Real Hopper/Ghidra, browser, or OS coverage: compiled CLI on Linux; native providers/GUI not needed or exercised.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: validate untrusted count against command-local capacity without allocation; preserve caller artifacts.

Review checklist

  • This PR addresses a concrete problem.
  • One focused outcome; Conventional Commit title.
  • Related issue is linked.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs/contracts/generated metadata require no changes.
  • Representative CLI output is described above.
  • Final diff checked for secrets, unrelated cleanup, and unsupported claims.

🔄 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/1784 **Author:** [@N0zoM1z0](https://github.com/N0zoM1z0) **Created:** 10/11/2026 **Status:** ✅ Merged **Merged:** 10/11/2026 **Merged by:** [@N0zoM1z0](https://github.com/N0zoM1z0) **Base:** `main` ← **Head:** `fix/1775-macho-build-version-tools` --- ### 📝 Commits (1) - [`6c386d3`](https://github.com/morluto/rea/commit/6c386d38065c82514f52914584acdc3fd0e742ee) fix(apple): validate build-version tool records within cmdsize ### 📊 Changes **2 files changed** (+73 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/artifacts/apple/MachoLoadCommandReader.ts` (+8 -1) 📝 `tests/boundary/cli/dylibResolutionCli.test.ts` (+65 -0) </details> ### 📄 Description ## Summary Report malformed Mach-O `LC_BUILD_VERSION` commands when their declared tool records do not fit inside `cmdsize`. Fixes #1775. ## Problem and expected behavior A 24-byte command with `ntools=1` previously produced parsed platform evidence despite having no tool record. The reader must validate the command's complete structure before accepting its platform. ## Change and scope Compare the declared count with the current command body's available 8-byte records, after checking its 24-byte header. This performs no count-driven allocation or iteration. Extra command padding remains accepted; unrelated load-command policies are unchanged. ## Contract and boundary impact - Semantic owner and earliest changed stage: Mach-O load-command decoding in `MachoLoadCommandReader`. - CLI and MCP/tool-catalog contract: no schema change; `trace-dylib-resolution` now reports these images as malformed. - Provider, bridge, target-format, or platform compatibility: offline Mach-O bytes; valid commands and unknown raw platform values remain supported. - Evidence, artifact, provenance, or reconstruction contract: preserve file identity and the parse failure; malformed images have no accepted slices and appear in partial coverage. - Process execution, authorization, cleanup, or containment impact: none. - Generated metadata, package, or installation impact: none; no generated outputs committed. ## Evidence and regression coverage - Tests added or updated: one compiled CLI scenario covers valid zero/one records, unknown platform, missing one/two records, maximum u32 count, and a truncated header. A sibling command and image trailer cannot satisfy a missing record. - Base reproduction: the added CLI test failed against unchanged production at `0bdc7a40a`: expected `malformed`, received `parsed`; nine existing CLI tests passed. - User-visible output: affected images expose `parse_status: "malformed"`, a reason naming `LC_BUILD_VERSION`, empty slices, and partial coverage. The CLI can still exit 0 while preserving those failures. - Remaining proof gaps: Linux synthetic file workflows; no actual dyld execution or native macOS provider validation. - [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 - `npm run test:focused -- src/artifacts/apple/MachoLoadCommandReader.test.ts tests/boundary/cli/dylibResolutionCli.test.ts` — reader 24/24 and new CLI regression passed; one pre-existing CLI scenario hit its 30-second timeout. - `npm run test:focused -- tests/boundary/cli/dylibResolutionCli.test.ts` — rerun passed 10/10 without changing timeouts. - `npm run check` — typecheck, lint/module boundaries, formatting, Knip, metadata and architecture guards passed after moving the new test outside the existing describe block to respect its line limit. ## Compatibility, safety, and release - Breaking changes or migration steps: none; reject malformed input rather than changing valid calls. - Real Hopper/Ghidra, browser, or OS coverage: compiled CLI on Linux; native providers/GUI not needed or exercised. - Package or release metadata impact: none. - Security, privacy, process, or containment review: validate untrusted count against command-local capacity without allocation; preserve caller artifacts. ## Review checklist - [x] This PR addresses a concrete problem. - [x] One focused outcome; Conventional Commit title. - [x] Related issue is linked. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs/contracts/generated metadata require no changes. - [x] Representative CLI output is described above. - [x] Final diff checked for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 00:55:19 +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#4814
No description provided.