Skip to content

Add YAML Mach-O parser fixtures#999

Merged
MikeMcQuaid merged 2 commits into
mainfrom
yaml2obj-macho-fixtures
Jul 13, 2026
Merged

Add YAML Mach-O parser fixtures#999
MikeMcQuaid merged 2 commits 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
@woodruffw

Copy link
Copy Markdown
Member

@copilot deconflict and rebase this PR.

auto-merge was automatically disabled July 13, 2026 17:43

Head branch was pushed to by a user without write access

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@copilot deconflict and rebase this PR.

Done in 6e3de18: I deconflicted the branch against main, resolved the test/test_macho.rb conflict, and pushed the updated branch.

Copilot AI requested a review from woodruffw July 13, 2026 17:44
@MikeMcQuaid MikeMcQuaid enabled auto-merge July 13, 2026 18:31
@MikeMcQuaid MikeMcQuaid merged commit ce5759a into main Jul 13, 2026
13 checks passed
@MikeMcQuaid MikeMcQuaid deleted the yaml2obj-macho-fixtures branch July 13, 2026 18:31
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

4 participants