Skip to content

fix(native): handle empty symbol batches in swift-demangle parser - #2875

Closed
vishalsatle wants to merge 6 commits into
morluto:mainfrom
vishalsatle:fix/swift-demangle-empty-input
Closed

vishalsatle wants to merge 6 commits into
morluto:mainfrom
vishalsatle:fix/swift-demangle-empty-input

Conversation

@vishalsatle

Copy link
Copy Markdown

Summary

This PR resolves an edge-case crash in parseDemangledSymbols when called with an empty symbol batch, and improves verify-module-boundaries.mjs resilience in non-git source environments.

Problem & Root Cause

  1. parseDemangledSymbols crash on empty input:
    When parameters.symbols is empty ([]), swift-demangle --compact -- outputs an empty string (""). In JavaScript, "".replace(/\n$/u, "").split("\n") produces [""] (array of length 1). The length check lines.length !== inputs.length (1 !== 0) fails and throws an unhandled TypeError: swift-demangle output count does not match input, causing tool call failures when processing empty symbol lists.

  2. verify-module-boundaries.mjs non-git failure:
    When running npm run lint or verify-module-boundaries from release archives or environments without .git, git ls-files unconditionally fails with fatal: not a git repository.

Proposed Solution

  • src/native/parsers/demangle.ts: Added an early return if (inputs.length === 0) return []; to safely return an empty array without running line-split operations. Exported DemangledSymbol type alias for consumer clarity.
  • src/native/parsers/demangle.test.ts: Added a dedicated Vitest test suite covering empty inputs ([], "", "\n"), standard demangled symbols, unchanged non-Swift symbols, invalid symbols, ordering preservation, and mismatched count validations.
  • scripts/verify-module-boundaries.mjs: Wrapped git ls-files in a fallback that uses readdir(..., { recursive: true }) when git is unavailable.

Test Plan

  • Unit test: parseDemangledSymbols([], "") returns []
  • Unit test: parseDemangledSymbols([], "\n") returns []
  • Unit test: Valid Swift demangle lines parse into { input, output, status: "demangled" }
  • Unit test: Unchanged non-Swift symbols parse with status: "unchanged"
  • Unit test: Invalid Swift symbols parse with status: "invalid"
  • Unit test: Mismatched output counts still throw TypeError
  • Boundary verification: node scripts/verify-module-boundaries.mjs passes in non-git environments

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T18:50:01.518075Z d5f2af8 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.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Low impact] The PR appears safe to merge; the only change is whitespace in a test.

Summary

The current PR only removes indentation before one test in src/native/parsers/demangle.test.ts. It does not change test behavior or the parser.

  • The invalid-symbol test declaration now starts at the left edge.

Reviews (9) · Last reviewed commit: "Merge branch 'main' into fix/swift-deman..." · Reviewed by Greptile

Comment thread scripts/verify-module-boundaries.mjs Resolved

@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: 778016fd36

ℹ️ 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/native/parsers/demangle.ts Resolved
Comment thread src/native/parsers/demangle.ts Resolved

@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: 00d76e976b

ℹ️ 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 scripts/verify-module-boundaries.mjs Resolved
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Source fixes and publication evidence for the review findings below. Tests and executable checks were skipped at the maintainer's request. Findings that still require a decision or execution evidence remain open.

review thread, review thread

The no-Git discovery test now covers nested forbidden imports; the shared Swift-symbol contract accepts empty batches, and the parser rejects unexpected output for empty input while preserving empty and one-newline zero-record outputs. Changes are live at 00d76e9. Pinned formatting and git diff --check passed; tests were not run.

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Source fixes and publication evidence for the review findings below. Tests and executable checks were skipped at the maintainer's request. Findings that still require a decision or execution evidence remain open.

review thread

git ls-files was allowed whenever Git succeeded, including from a non-Git archive nested under an ancestor repository. An ignored archive could therefore produce an empty file list and a false-success zero-file scan. Discovery now checks git rev-parse --show-cdup and trusts Git only when the verifier root is the repository root; otherwise it scans the archive’s source tree. I added a regression for an ignored archive beneath an ancestor worktree. Targeted formatting and git diff --check passed; tests were not run under the wave instructions. Published at 973e8ea.

@morluto
morluto force-pushed the fix/swift-demangle-empty-input branch from 973e8ea to f1d4d2b Compare October 13, 2026 18:10
@morluto
morluto force-pushed the fix/swift-demangle-empty-input branch 2 times, most recently from 29d5601 to 3198660 Compare October 13, 2026 18:31
vishalsatle and others added 5 commits October 14, 2026 02:43
…o inputs

When demangle_swift is called with an empty symbol list, parseDemangledSymbols
split empty stdout ("") into [""], failing the input count equality check
and throwing an unhandled TypeError.

Add a zero-length guard for inputs and add comprehensive unit test coverage.
Also add fallback directory traversal in verify-module-boundaries when git is unavailable.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@morluto
morluto force-pushed the fix/swift-demangle-empty-input branch from 3198660 to d5f2af8 Compare October 13, 2026 18:43
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels Oct 14, 2026
morluto added a commit that referenced this pull request Oct 14, 2026
Preserve XML and Interface Builder identity at their parsing boundary, retain usable Objective-C slots with precise coverage, and keep native trace failures distinct from absence. Add caller-selected Interface Builder summaries backed by complete retained Evidence, and preserve comparison limitations.

Reviewed fixes: #1969, #2088, #2108, #2513, #2639, #2684, #2731, #2759, #2875, #2888, #2889, #2970, #2971, #3002.

Validation: relevant native/domain focused lane passed 142 tests; earlier Interface Builder/MCP checks passed 24 tests. Real native UI and Ghidra producer coverage was not repeated.
@vishalsatle

Copy link
Copy Markdown
Author

Hi @morluto, thanks for reviewing this PR and updating the tests! I noticed #2875 was listed under Reviewed fixes in commit 55dd21a on main. Will this PR still be merged directly, or were the changes already folded into that commit? If possible, merging the PR branch (or including a Co-authored-by: trailer) so GitHub records the contributor credit would be greatly appreciated!

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

Copy link
Copy Markdown
Contributor

Heads up: main already has this change in 55dd21a. The code is in src/native/parsers/demangle.ts, and returns an empty array when given an empty input list covers it. It is listed on tracker #3582. If this PR still adds something main doesn't have, please say so here and I'll take it off the list. Thanks for the fix!

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Thanks @vishalsatle. Closing this PR as superseded by 55dd21a5e on main.

The empty Swift-demangle batch behavior and its regression already exist on main; the current branch adds no new behavior.

This is an unmerged closure: it does not label this PR as merged or remove contributor history/credit. The decision uses the current source diff and existing validation record; no new local test or provider run is claimed.

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.

3 participants