Skip to content

fix(native): reject required otool fields truncated before their value - #1995

Merged
morluto merged 3 commits into
mainfrom
fix/issue-1990
Oct 12, 2026
Merged

morluto merged 3 commits into
mainfrom
fix/issue-1990

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Fixes #1990

Behavior

#1967 changed requireUniqueField's pattern to ^\s*<key>(?:\s|$), so the empty dylib-use options row counts as present. The pattern applies to every required field. Truncated otool -l output with a bare vmaddr, vmsize, uuid or entryoff label therefore passed the presence check, parseField dropped the line, and the value silently became null. A missing UUID then read as "no LC_UUID". Such output is now rejected with otool field <key> has no value, and an empty options row is still accepted.

Related cleanup

requireUniqueField used its own regex to decide which line holds a field. Now parseField, which already owns field-line parsing (including the empty-options exception), decides whether the single matching line carries a value. The label regex is still used only to detect missing or repeated labels, so the existing missing or repeated diagnostics are unchanged.

Validation

  • New cases in tests/boundary/providers/native/nativeLoadKinds.golden.test.ts truncate one required value at a time in the real otool-load.txt capture. All four fail on main (the output is accepted) and pass here. The existing empty-options and repeated-options cases still pass.
  • tests/boundary/providers/native and src/native: 319 passed. The one failure is the local hdiutil verify refusal, which also fails on main on this Mac.
  • npm run lint, npm run typecheck, npm run format:check: pass.
  • npm test: 8,500 passed, 12 failed. These are the same 12 that fail on a clean origin/main worktree on this Mac: ibtool NIB tests, the hdiutil verify refusal, and JS runtime paths under /private/var.
  • Not re-verified against live otool output; the fixture is a real capture.

🤖 Generated with Claude Code

#1967 let requireUniqueField count a label at end of line so an empty
dylib-use options row is present. That applied to every required field,
so truncated output such as a bare vmaddr, vmsize, uuid or entryoff line
passed the presence check while parseField dropped it, and the value
silently became null.

Let parseField decide which labeled line carries a value: the single
matching line must parse as that field. The empty options row remains
the only valueless field parseField admits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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-12T00:48:07.934434Z 4e3cecf 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: 27a4d14a01

ℹ️ 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".

throw new TypeError(`otool field ${key} is missing or repeated`);
// parseField owns which labeled lines carry a value; a bare required label
// is truncated output, except the empty dylib-use options row it admits.
if (parseField(lines[0] ?? "")?.[0] !== key)

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 Allow empty segment names in Mach-O object files

Mach-O MH_OBJECT files intentionally put their sections in an unnamed segment, and otool -l emits that as a bare segname row. Every segment validates segname through this helper, so this new check rejects otherwise valid object-file output as malformed and makes inspect_macho fail for those targets; the previous implementation retained the segment with an unknown name. Treat an empty segname as a valid textual value rather than as truncated output.

AGENTS.md reference: AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Confirmed with a real clang -c object: otool -l prints its unnamed MH_OBJECT segment as a bare segname row, and this branch rejected it as unreadable. Fixed in ad89028. parseField now admits an empty segname alongside the empty dylib-use options row, and the projection still reports the empty name as "unknown", as main does. inspect-macho on that object now succeeds, with segment output identical to main. A truncated vmaddr in the same command is still rejected (new test in nativeLoadKinds.golden.test.ts). Full npm test: only this Mac's 12 environmental baseline failures.

MH_OBJECT files put their sections in one segment whose name is empty,
and otool -l prints it as a bare segname label. Requiring a value for
every scalar field rejected valid object-file output as unreadable.

Let parseField admit an empty segname like the empty dylib-use options
row, and keep projecting an empty or absent segment name as "unknown",
as main did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

ℹ️ 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 thread src/native/parsers/otool.ts Outdated
if (line === "options") return ["options", ""];
// A dylib-use command with no flags still has an empty options row, and
// MH_OBJECT files put their sections in a segment with an empty segname.
if (line === "options" || line === "segname") return [line, ""];

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 Preserve empty section names

When otool reports an all-NUL section_64.sectname, it emits the same bare sectname row that this change already handles for segname. requireUniqueField now finds that label but parseField returns undefined, causing inspect_macho to reject an otherwise structurally readable Mach-O instead of retaining the section with its prior unknown name. Add sectname to the intentional empty-name handling (and project it to unknown) so this valid unknown value is preserved.

AGENTS.md reference: AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 4e3cecf. parseField admits a bare sectname the same way as segname (both are fixed char[16] fields that may be all NUL), and the section projection keeps the empty name as "unknown", as main does. The object-file test now also covers an empty sectname, which fails without this change with otool field sectname has no value. The other string fields (name, path) always print an offset suffix, so they cannot appear bare. Full npm test: only this Mac's 12 environmental baseline failures.

An all-NUL section_64.sectname prints as a bare sectname label, like an
empty segname. Admit it in parseField and keep projecting the empty name
as "unknown", as main did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto
morluto merged commit adde8a8 into main Oct 12, 2026
29 checks passed
@morluto
morluto deleted the fix/issue-1990 branch October 12, 2026 00:55
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
3 tasks done
@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
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.

otool parser accepts required load-command fields with no value (truncated output becomes null)

2 participants