Skip to content

fix(mach): detect shebang scripts before Mach-O parsing#533

Merged
m4b merged 1 commit into
m4b:masterfrom
wyf027:fix-mach-shebang-detection-494
May 25, 2026
Merged

fix(mach): detect shebang scripts before Mach-O parsing#533
m4b merged 1 commit into
m4b:masterfrom
wyf027:fix-mach-shebang-detection-494

Conversation

@wyf027

@wyf027 wyf027 commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When scanning macOS directories, many non-Mach-O files are shell scripts whose first four bytes look like invalid Mach magic (e.g. 0x23212f75 for #!/u).
  • Detect inputs starting with #! early in Mach::parse and return a clear Malformed error instead of Invalid magic number.

Fixes #494

Test plan

  • cargo test --lib mach::test::parse_rejects_shebang_scripts
  • Existing Mach-O fat binary/archive parse tests still pass

Shell scripts on macOS were reported as opaque "Invalid magic number"
errors (e.g. 0x23212f75 for `#!/u`). Reject inputs starting with `#!`
with a clear Malformed error instead.

Fixes m4b#494

Co-authored-by: Cursor <cursoragent@cursor.com>

@m4b m4b left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

thank you

@m4b m4b merged commit 698e71a into m4b:master May 25, 2026
5 checks passed
@m4b

m4b commented May 25, 2026

Copy link
Copy Markdown
Owner

NB: backwards compatible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid magic number for many mach-o executables.

2 participants