[PR #6842] [MERGED] fix(native): preserve whitespace in Mach-O segment and section names #7424

Closed
opened 2026-11-01 21:47:46 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6842
Author: @Abelo9996
Created: 10/23/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @gensokyo-dev

Base: main ← Head: fix-6818-macho-name-whitespace


📝 Commits (2)

  • 07bf508 fix(native): preserve whitespace in Mach-O segment and section names
  • 6ad86e9 Merge branch 'main' into fix-6818-macho-name-whitespace

📊 Changes

2 files changed (+53 additions, -0 deletions)

View changed files

📝 src/native/parsers/otool.ts (+9 -0)
📝 tests/boundary/providers/native/nativeLoadKinds.golden.test.ts (+44 -0)

📄 Description

Summary

Fixes #6818.

parseOtoolLoadCommands trimmed the value of every otool field, so a section named " sec " in segment " seg " came back as "sec" and "seg". Mach-O stores these as fixed-width names, and machoName already documents its result as the name exactly as observed, so whitespace-distinct names could become indistinguishable. Segment and section names now keep their surrounding spaces. Ordinary names, the empty segment name of an object file, and numeric field parsing are unchanged.

Problem and expected behavior

otool -l prints segname and sectname as the label, one separator space, then the stored name. For the issue's 192-byte object, the real otool -h -l lines are:

  segname 
  sectname  sec 
   segname  seg 

parseField trims the whole line, matches the label with \s+, and trims the captured value again, so the spaces that belong to the name are dropped. TEXT_FIELDS keeps these fields from numeric coercion but does nothing for whitespace. Expected: { segment: " seg ", name: " sec " }, with the same values in the raw segname command field.

Change and scope

parseField gets one more exact-format branch next to the existing name/path (offset N) one: for a line whose label is segname or sectname, it drops only the indentation and the single separator space and returns the rest verbatim. A bare label still yields the empty string, so the unnamed object-file segment (#3875) and the version names (#5680) keep working. Other fields still go through the generic trimmed path.

Follow the contribution scope.
Scope decision: not applicable (ordinary fix within existing boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: parseField in src/native/parsers/otool.ts, while turning otool load-command lines into fields.
  • Contribution scope fit and linked maintainer decision: ordinary bug fix, not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. segments[].name, sections[].segment, sections[].name and the raw load_commands[].fields.segname/sectname now carry the name with its surrounding spaces. Names without surrounding whitespace are unchanged.
  • Provider, bridge, target-format, or platform compatibility: native macOS provider only (otool output). No other provider touched.
  • Evidence, artifact, provenance, or reconstruction contract: the normalized names now match the observed otool output instead of a trimmed form.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): unchanged.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

(The existing static provider reads files and launches inspection tools; this change only corrects parsing of their captured output.)

Evidence and regression coverage

  • Tests added or updated: tests/boundary/providers/native/nativeLoadKinds.golden.test.ts gets "keeps the surrounding spaces of segment and section names". It parses the otool output captured from the issue's object and expects { name: "", sections: [{ segment: " seg ", name: " sec " }] }, then gives the segment itself the name " seg " and checks both commands[0].fields.segname and segments[0].name.

  • Base reproduction (executed): with the test and without the fix:

    × keeps the surrounding spaces of segment and section names
    -         "name": " sec ",
    -         "segment": " seg ",
    +         "name": "sec",
    +         "segment": "seg",
          Tests  1 failed | 62 passed (63)
    

    With the fix: Tests 63 passed (63).

    The issue's repro.mjs, run with macOS otool in place of llvm-otool, against the origin/main parser and then this branch:

    -- origin/main parser
    Encoded names: {"name":" sec ","segment":" seg "}
    Producer fields: ["  segname ","  sectname  sec ","   segname  seg "]
    REA names: {"name":"sec","segment":"seg"}
    Producer exit: 0
    -- branch parser
    Encoded names: {"name":" sec ","segment":" seg "}
    Producer fields: ["  segname ","  sectname  sec ","   segname  seg "]
    REA names: {"name":" sec ","segment":" seg "}
    Producer exit: 0
    
  • User-visible CLI/MCP output (if applicable): inspect-macho on the issue's fixture against a freshly compiled runtime (scripts/rea.mjs), filtered to the segments.

    Before:

    $ rea inspect-macho fixture.o --format json --filter-output normalized_result.segments.items
    {"normalized_result":{"segments":{"items":[{"name":"","vm_address":"0x0","vm_size":8,"file_offset":184,"file_size":8,"maximum_permissions":{"read":true,"write":true,"execute":true,"raw":"7"},"initial_permissions":{"read":true,"write":true,"execute":true,"raw":"7"},"sections":{"items":[{"segment":"seg","name":"sec","address":"0x0","size":8,"file_offset":184,"alignment":1,"flags":["0"]}],"total":1,"exhaustive":true,"limitations":[]}}]}}}
    exit=0
    

    After:

    $ rea inspect-macho fixture.o --format json --filter-output normalized_result.segments.items
    {"normalized_result":{"segments":{"items":[{"name":"","vm_address":"0x0","vm_size":8,"file_offset":184,"file_size":8,"maximum_permissions":{"read":true,"write":true,"execute":true,"raw":"7"},"initial_permissions":{"read":true,"write":true,"execute":true,"raw":"7"},"sections":{"items":[{"segment":" seg ","name":" sec ","address":"0x0","size":8,"file_offset":184,"alignment":1,"flags":["0"]}],"total":1,"exhaustive":true,"limitations":[]}}]}}}
    exit=0
    

    As a control, inspect-macho /bin/ls after the fix still reports __PAGEZERO, __TEXT (__text, __auth_stubs, __const, __cstring, __unwind_info), __DATA_CONST, __DATA and __LINKEDIT with the usual names.

  • Remaining proof gaps: MCP transport was not run by hand; it uses the same parser. Only macOS otool (cctools-1030.6.3, which runs llvm-otool) was used as the producer; the issue's Linux llvm-otool 23.1.3 run was not repeated.

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

Run with Node 24.18.0 on macOS arm64.

  • npm run test:focused -- tests/boundary/providers/native/nativeLoadKinds.golden.test.ts: 63 passed (1 failed without the fix, shown above)
  • npm run test:focused -- over src/native/NativeMachoInspection.test.ts and the otool-related files in tests/boundary/providers/native/ (nativeLoadText, nativeReexport, nativeInventory, nativeTextRobustness, nativeMachoHeader, nativeSelectedArchitecture, nativeMachoUuidlessInspection, nativeProvider, nativeLoadKinds) plus tests/boundary/cli/nativeMachoEchoedPathCli.test.ts: 11 files, 233 passed
  • npm run check tasks run individually: typecheck, lint:built (0 errors), knip, metadata:check and verify:architecture-guards passed. format:check was run as oxfmt --check on the changed files (clean), because the repo-wide run in my checkout also picks up unrelated untracked local notes.
  • npm run compile, then the CLI commands above.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. A client that compared trimmed names will now see the stored name for the rare section or segment whose name has surrounding spaces.
  • Real Hopper/Ghidra, browser, or OS coverage: macOS only; no engine involved.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new data exposed; the name was already in the raw otool output.

Author readiness

Human owner: @Abelo9996

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • 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.

🔄 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/6842 **Author:** [@Abelo9996](https://github.com/Abelo9996) **Created:** 10/23/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@gensokyo-dev](https://github.com/gensokyo-dev) **Base:** `main` ← **Head:** `fix-6818-macho-name-whitespace` --- ### 📝 Commits (2) - [`07bf508`](https://github.com/morluto/rea/commit/07bf508c55eac406a52831063a3971afb15105e8) fix(native): preserve whitespace in Mach-O segment and section names - [`6ad86e9`](https://github.com/morluto/rea/commit/6ad86e9560f99917133aab923bcbdc1cac954a63) Merge branch 'main' into fix-6818-macho-name-whitespace ### 📊 Changes **2 files changed** (+53 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/native/parsers/otool.ts` (+9 -0) 📝 `tests/boundary/providers/native/nativeLoadKinds.golden.test.ts` (+44 -0) </details> ### 📄 Description ## Summary Fixes #6818. `parseOtoolLoadCommands` trimmed the value of every otool field, so a section named `" sec "` in segment `" seg "` came back as `"sec"` and `"seg"`. Mach-O stores these as fixed-width names, and `machoName` already documents its result as the name exactly as observed, so whitespace-distinct names could become indistinguishable. Segment and section names now keep their surrounding spaces. Ordinary names, the empty segment name of an object file, and numeric field parsing are unchanged. ## Problem and expected behavior `otool -l` prints `segname` and `sectname` as the label, one separator space, then the stored name. For the issue's 192-byte object, the real `otool -h -l` lines are: ``` segname sectname sec segname seg ``` `parseField` trims the whole line, matches the label with `\s+`, and trims the captured value again, so the spaces that belong to the name are dropped. `TEXT_FIELDS` keeps these fields from numeric coercion but does nothing for whitespace. Expected: `{ segment: " seg ", name: " sec " }`, with the same values in the raw `segname` command field. ## Change and scope `parseField` gets one more exact-format branch next to the existing `name`/`path (offset N)` one: for a line whose label is `segname` or `sectname`, it drops only the indentation and the single separator space and returns the rest verbatim. A bare label still yields the empty string, so the unnamed object-file segment (#3875) and the `version` names (#5680) keep working. Other fields still go through the generic trimmed path. Follow the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope). Scope decision: not applicable (ordinary fix within existing boundaries). ## Contract and boundary impact - Semantic owner and earliest changed stage: `parseField` in `src/native/parsers/otool.ts`, while turning otool load-command lines into fields. - Contribution scope fit and linked maintainer decision: ordinary bug fix, not applicable. - CLI and MCP/tool-catalog contract: no schema change. `segments[].name`, `sections[].segment`, `sections[].name` and the raw `load_commands[].fields.segname`/`sectname` now carry the name with its surrounding spaces. Names without surrounding whitespace are unchanged. - Provider, bridge, target-format, or platform compatibility: native macOS provider only (otool output). No other provider touched. - Evidence, artifact, provenance, or reconstruction contract: the normalized names now match the observed otool output instead of a trimmed form. - Target selection, authority, upstream behavior, and cleanup details (if applicable): unchanged. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact (CI generates and validates ignored catalogs and `skills/`; edit authored instructions in `.agents/skills/reverse-engineer-anything/` and never commit build outputs): none. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [x] Read existing files or captured data. - [x] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. (The existing static provider reads files and launches inspection tools; this change only corrects parsing of their captured output.) ## Evidence and regression coverage - Tests added or updated: `tests/boundary/providers/native/nativeLoadKinds.golden.test.ts` gets "keeps the surrounding spaces of segment and section names". It parses the otool output captured from the issue's object and expects `{ name: "", sections: [{ segment: " seg ", name: " sec " }] }`, then gives the segment itself the name `" seg "` and checks both `commands[0].fields.segname` and `segments[0].name`. - Base reproduction (executed): with the test and without the fix: ``` × keeps the surrounding spaces of segment and section names - "name": " sec ", - "segment": " seg ", + "name": "sec", + "segment": "seg", Tests 1 failed | 62 passed (63) ``` With the fix: `Tests 63 passed (63)`. The issue's `repro.mjs`, run with macOS `otool` in place of `llvm-otool`, against the `origin/main` parser and then this branch: ``` -- origin/main parser Encoded names: {"name":" sec ","segment":" seg "} Producer fields: [" segname "," sectname sec "," segname seg "] REA names: {"name":"sec","segment":"seg"} Producer exit: 0 -- branch parser Encoded names: {"name":" sec ","segment":" seg "} Producer fields: [" segname "," sectname sec "," segname seg "] REA names: {"name":" sec ","segment":" seg "} Producer exit: 0 ``` - User-visible CLI/MCP output (if applicable): `inspect-macho` on the issue's fixture against a freshly compiled runtime (`scripts/rea.mjs`), filtered to the segments. Before: ``` $ rea inspect-macho fixture.o --format json --filter-output normalized_result.segments.items {"normalized_result":{"segments":{"items":[{"name":"","vm_address":"0x0","vm_size":8,"file_offset":184,"file_size":8,"maximum_permissions":{"read":true,"write":true,"execute":true,"raw":"7"},"initial_permissions":{"read":true,"write":true,"execute":true,"raw":"7"},"sections":{"items":[{"segment":"seg","name":"sec","address":"0x0","size":8,"file_offset":184,"alignment":1,"flags":["0"]}],"total":1,"exhaustive":true,"limitations":[]}}]}}} exit=0 ``` After: ``` $ rea inspect-macho fixture.o --format json --filter-output normalized_result.segments.items {"normalized_result":{"segments":{"items":[{"name":"","vm_address":"0x0","vm_size":8,"file_offset":184,"file_size":8,"maximum_permissions":{"read":true,"write":true,"execute":true,"raw":"7"},"initial_permissions":{"read":true,"write":true,"execute":true,"raw":"7"},"sections":{"items":[{"segment":" seg ","name":" sec ","address":"0x0","size":8,"file_offset":184,"alignment":1,"flags":["0"]}],"total":1,"exhaustive":true,"limitations":[]}}]}}} exit=0 ``` As a control, `inspect-macho /bin/ls` after the fix still reports `__PAGEZERO`, `__TEXT` (`__text`, `__auth_stubs`, `__const`, `__cstring`, `__unwind_info`), `__DATA_CONST`, `__DATA` and `__LINKEDIT` with the usual names. - Remaining proof gaps: MCP transport was not run by hand; it uses the same parser. Only macOS `otool` (cctools-1030.6.3, which runs `llvm-otool`) was used as the producer; the issue's Linux `llvm-otool` 23.1.3 run was not repeated. For evidence-bearing changes: - [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 Run with Node 24.18.0 on macOS arm64. - `npm run test:focused -- tests/boundary/providers/native/nativeLoadKinds.golden.test.ts`: 63 passed (1 failed without the fix, shown above) - `npm run test:focused --` over `src/native/NativeMachoInspection.test.ts` and the otool-related files in `tests/boundary/providers/native/` (`nativeLoadText`, `nativeReexport`, `nativeInventory`, `nativeTextRobustness`, `nativeMachoHeader`, `nativeSelectedArchitecture`, `nativeMachoUuidlessInspection`, `nativeProvider`, `nativeLoadKinds`) plus `tests/boundary/cli/nativeMachoEchoedPathCli.test.ts`: 11 files, 233 passed - `npm run check` tasks run individually: `typecheck`, `lint:built` (0 errors), `knip`, `metadata:check` and `verify:architecture-guards` passed. `format:check` was run as `oxfmt --check` on the changed files (clean), because the repo-wide run in my checkout also picks up unrelated untracked local notes. - `npm run compile`, then the CLI commands above. ## Compatibility, safety, and release - Breaking changes or migration steps: none. A client that compared trimmed names will now see the stored name for the rare section or segment whose name has surrounding spaces. - Real Hopper/Ghidra, browser, or OS coverage: macOS only; no engine involved. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new data exposed; the name was already in the raw otool output. ## Author readiness Human owner: @Abelo9996 - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff 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-11-01 21:47:46 +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#7424
No description provided.