Add YAML Mach-O parser fixtures#999
Open
MikeMcQuaid wants to merge 1 commit into
Open
Conversation
- Cover malformed command sizes, bounds and string offsets. - Exercise byte order, build metadata and runtime paths.
There was a problem hiding this comment.
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
cmdsizevalues (unaligned, out-of-bounds, smaller than the command structure). - Add
LCStrvalidation to reject malformed string offsets within load commands. - Add
yaml2objYAML sources and prebuilt.machofixtures, 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #201