Skip to content

Validate FatArch alignment and reject truncated Fat architecture records - #1030

Merged
p-linnane merged 3 commits into
Homebrew:mainfrom
alebcay:fat-arch-alignment
Sep 7, 2026
Merged

p-linnane merged 3 commits into
Homebrew:mainfrom
alebcay:fat-arch-alignment

Conversation

@alebcay

@alebcay alebcay commented Sep 7, 2026

Copy link
Copy Markdown
Member
  • Add parse-time validation for Fat architecture alignment exponent (align <= 15) to prevent excessive padding allocation during Fat file reconstruction and signing
  • Harden populate_fat_archs to check record length before unpacking; truncated FatArch/FatArch64 records now raise TruncatedFileError instead of NoMethodError
  • Add regression tests for truncated 32-bit and 64-bit Fat architecture records

Signed-off-by: Caleb Xu <calebcenter@live.com>
Assisted-by: OpenCode (Nemotron 3 Ultra)
Reject alignment values exceeding MAX_FAT_ARCH_ALIGN (15) in
populate_fat_archs to prevent excessive padding allocation during
Fat file reconstruction and signing.

Signed-off-by: Caleb Xu <calebcenter@live.com>
Assisted-by: OpenCode (Nemotron 3 Ultra)
Copilot AI balanced review requested due to automatic review settings September 7, 2026 04:08

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.

馃煛 Changes recommended

Unused test assignments will fail the repository鈥檚 default RuboCop check.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Hardens Fat Mach-O parsing against unsafe alignments and truncated architecture records.

Changes:

  • Rejects alignment exponents above 15.
  • Detects truncated 32-bit and 64-bit records.
  • Adds parsing and code-signing regression tests.
File summaries
File Reviewed changes and findings
test/test_fat.rb Adds malformed-record tests. Critical: Remove unused assignments on lines 69 and 90; RuboCop will fail.
test/test_code_signing.rb Tests safe signing failure. No issues found.
lib/macho/headers.rb Defines the maximum alignment exponent. No issues found.
lib/macho/fat_file.rb Validates record lengths and alignments. Nit: Document the new FatArchAlignmentError raise.
lib/macho/exceptions.rb Adds the alignment error type. No issues found.
Review details

Suppressed comments (2)

lib/macho/fat_file.rb:374

  • The updated raise documentation covers truncation but omits the new FatArchAlignmentError raised directly by this method. Add it so callers of this public-but-private-API parser method can see both newly enforced failure modes.
    # @raise [TruncatedFileError] if the file is too small to contain all fat architectures

test/test_fat.rb:90

  • This local is also never read and will be reported by the RuboCop check as Lint/UselessAssignment. Remove it so the repository check can pass.
    fat_arch64_size = MachO::Headers::FatArch64.bytesize
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/test_fat.rb
- test_invalid_fat_arch_alignment_32: reject FAT_MAGIC with align > 15
- test_invalid_fat_arch_alignment_64: reject FAT_MAGIC_64 with align > 15
- test_max_valid_fat_arch_alignment_accepted: accept align == 15
- test_rejects_invalid_fat_alignment_before_signing: end-to-end test
  verifying file is not modified when alignment is invalid

Signed-off-by: Caleb Xu <calebcenter@live.com>
Assisted-by: OpenCode (Nemotron 3 Ultra)

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.

馃煝 Approval recommended

The defensive checks and regression coverage introduce no unresolved issues.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@p-linnane p-linnane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome, thanks @alebcay!

@p-linnane
p-linnane merged commit 86da59b into Homebrew:main Sep 7, 2026
12 checks passed
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.

3 participants