Add YAML Mach-O parser fixtures#999
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.
|
@copilot deconflict and rebase this PR. |
Head branch was pushed to by a user without write access
Done in |
Fixes #201