Skip to content

Add YAML Mach-O parser fixtures#999

Open
MikeMcQuaid wants to merge 1 commit into
mainfrom
yaml2obj-macho-fixtures
Open

Add YAML Mach-O parser fixtures#999
MikeMcQuaid wants to merge 1 commit into
mainfrom
yaml2obj-macho-fixtures

Conversation

@MikeMcQuaid

Copy link
Copy Markdown
Member
  • Cover malformed command sizes, bounds and string offsets.
  • Exercise byte order, build metadata and runtime paths.

Fixes #201

- Cover malformed command sizes, bounds and string offsets.
- Exercise byte order, build metadata and runtime paths.
Copilot AI review requested due to automatic review settings July 10, 2026 18:46

Copilot AI 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.

Pull request overview

This PR expands the Mach-O parser’s resilience and test coverage by adding yaml2obj-generated fixtures and corresponding tests for malformed load command sizing/bounds and malformed lc_str offsets, plus a few sanity-check “known good” fixture cases (endianness, build metadata, rpaths).

Changes:

  • Add parser validations for truncated load-command regions and invalid cmdsize values (unaligned, out-of-bounds, smaller than the command structure).
  • Add LCStr validation to reject malformed string offsets within load commands.
  • Add yaml2obj YAML sources and prebuilt .macho fixtures, plus new tests covering the above cases.

Reviewed changes

Copilot reviewed 4 out of 25 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/test_macho.rb Adds regression tests for invalid load command sizes/bounds, malformed lc_str offsets, and a few minimal/endianness/build-version/rpath fixture checks.
lib/macho/macho_file.rb Hardens load command parsing by validating declared command region length, per-command truncation, alignment, and size bounds before parsing.
lib/macho/load_commands.rb Adds strict LCStr offset validation to raise a targeted error for malformed load-command strings.
lib/macho/exceptions.rb Introduces LoadCommandSizeError for invalid cmdsize cases.
test/bin/yaml2obj/Makefile Adds a simple build rule to generate .macho fixtures from the YAML sources via yaml2obj.
test/bin/yaml2obj/load-cmdsize-too-small.yaml YAML source for a fixture with cmdsize smaller than the command structure.
test/bin/yaml2obj/load-cmdsize-too-large.yaml YAML source for a fixture with cmdsize exceeding the declared load-command region.
test/bin/yaml2obj/truncated-load-commands.yaml YAML source for a fixture where ncmds is declared but sizeofcmds is zero.
test/bin/yaml2obj/truncated-load-command-region.yaml YAML source for a fixture where sizeofcmds exceeds available file data.
test/bin/yaml2obj/unaligned-cmdsize.yaml YAML source for a fixture with an unaligned load command size.
test/bin/yaml2obj/invalid-lcstr-offset.yaml YAML source for a fixture with an invalid lc_str offset (e.g., 0).
test/bin/yaml2obj/minimal.yaml YAML source for a minimal valid Mach-O fixture.
test/bin/yaml2obj/big-endian.yaml YAML source for a big-endian fixture to exercise byte order parsing.
test/bin/yaml2obj/build-version.yaml YAML source for a fixture containing LC_BUILD_VERSION metadata.
test/bin/yaml2obj/rpath.yaml YAML source for a fixture containing an LC_RPATH command.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MikeMcQuaid MikeMcQuaid enabled auto-merge July 10, 2026 18:54
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.

Use yaml2obj to generate more test cases

2 participants