Repository navigation
Check for room before touching the Mach-O header - #5
Open
TartanLeGrand wants to merge 7 commits into
Open
TartanLeGrand wants to merge 7 commits into
TartanLeGrand wants to merge 7 commits into
Conversation
ReallocCodeSignSpace resized __LINKEDIT (through the shared mapping, so in the file itself) before finding out that there was no room for LC_CODE_SIGNATURE, leaving a corrupted header behind on failure. Test for room first. The room left by the load commands was measured up to the __text section only, so a binary without one always reported none, headerpad or not. Measure it up to the first section of any segment.
3 tasks done
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
5 of 7 tasks
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.
What does this PR do?
Fixes two problems behind ">>> Can't find free space of LoadCommands for CodeSignature!", both in
ZArchO:__textonly.Initcomputed the room left after the load commands from the offset of the__textsection. A binary without__text(for example an app extension whose code was dead-stripped) always reported zero, however much padding it had: with-headerpad_max_install_namesand about 15 KB actually free, signing still failed. The room is now measured up to the first section with content in any segment (non-zero offset and size, so zerofill sections are ignored).ReallocCodeSignSpaceresized__LINKEDITfirst and only then found out there was no room forLC_CODE_SIGNATURE. Since the header is a shared mapping of the file, a failure left a half-applied, corrupted header in the binary. The check now happens before the first write, and it compares against the size of thecodesignature_commandit writes (16 bytes) instead of 4.This overlaps with #2, which addresses the first point (smallest gap over all sections); I left a note there. This PR also skips empty sections and fixes the second point. Happy to fold it into #2 or rebase on it, whichever you prefer.
How was it tested?
zsign has no test suite of its own; these run in xtool against hand-built Mach-O fixtures (
SignerLayoutTests, part of xtool-org/xtool#326), with xtool depending on this branch (Linux x86_64, Podman):__textsigns. Fails on 1.9.0, passes with this change.swift buildof theZupersigntarget on this branch alone.Not tested: the standalone zsign builds (
linux/,macos/,windows/) and fat binaries specifically.Known remaining edge: if writing the new file fails after the checks, the header edits already made through the mapping are not rolled back.
Developed with AI assistance; validated on device and against App Store Connect as described in #3 and #4.