fix(setup): truncate Bun trailing padding before codesign; stop false-alarm Apple Silicon warning#1758
Open
brandonlipman wants to merge 1 commit into
Open
Conversation
…-alarm warning On Apple Silicon, `./setup` warned "codesign failed for browse/dist/find-browse (binary may not run on Apple Silicon)" and the same for bin/gstack-global-discover. The binaries actually run fine — the warning was a false alarm. Root cause: `bun build --compile` leaves ~19KB of trailing zero-padding AFTER the Mach-O LC_CODE_SIGNATURE region for these two binaries (browse/design/pdf have 0 trailing bytes). macOS codesign requires the signature to be the last content and extend to EOF, so the padding makes `codesign --remove-signature` fail with "internal error in Code Signing subsystem" and `codesign -s - -f` fail with "main executable failed strict validation". The re-sign fails, leaving Bun's original adhoc linker-signed signature in place — which still satisfies the kernel's exec-time check, so the binary runs despite `codesign --verify` being unhappy. Fix (two parts): 1. Truncate trailing bytes past LC_CODE_SIGNATURE (computed via otool dataoff+ datasize) before signing. Verified: the identical `codesign -s - -f` that failed on the full file succeeds on the truncated file, and `codesign --verify --strict` then passes. Degrades safely if otool is unavailable. 2. When re-sign still fails, probe the binary and reserve the scary "may not run" warning for genuine SIGKILL (exit 137); otherwise emit an informational note. Probe is set -e safe (`|| _probe_rc=$?`). Adds two regression tests to test/setup-codesign.test.ts (truncation logic + SIGKILL-gated warning). Both fail on the pre-fix setup. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Symptom
On Apple Silicon,
./setupprints:Both binaries run fine — the warning is a false alarm.
browse,design, andpdfnever warn.Root cause
bun build --compileleaves ~19 KB of trailing zero-padding after the Mach-OLC_CODE_SIGNATUREregion forfind-browseandgstack-global-discover(verified:browse/design/pdfhave 0 trailing bytes). macOS codesign requires the signature to be the last content and extend to EOF, so the padding makes both setup steps fail:codesign --remove-signature→internal error in Code Signing subsystemcodesign -s - -f→main executable failed strict validationThe re-sign fails, leaving Bun's original adhoc linker-signed signature in place. That signature still covers the executable code pages, so the kernel's exec-time check passes and the binary runs — even though
codesign --verifyis unhappy.Measured (signature end vs file size):
codesign --verifyConfirmation test: truncating a copy of
find-browseto the signature end makes the identicalcodesign -s - -fsucceed andcodesign --verify --strictpass, and the binary still runs.Fix
setup(theDarwin+arm64codesign loop):LC_CODE_SIGNATURE(offset fromotooldataoff+datasize) before signing. Degrades safely ifotoolis unavailable or there is no trailing slack.exit 137(SIGKILL); otherwise emit an informational note. The probe isset -esafe (|| _probe_rc=$?).Tests
Two regression tests added to
test/setup-codesign.test.ts(truncation logic + SIGKILL-gated warning). Both fail on the pre-fixsetup. Full suite: 8 pass / 0 fail.🤖 Generated with Claude Code