authorgravatar for paulofernandobd@gmail.comPaulo Duarte <paulofernandobd@gmail.com> 2026-06-28 15:18:48+01:00
committergravatar for paulofernandobd@gmail.comPaulo Duarte <paulofernandobd@gmail.com> 2026-07-15 04:08:44+01:00
log9908b10d928a12731a288bd59068151d386efdac
treef654d726c7fcb7eeed74772b922a7482d446fcfc
parent64dfaa568db04aedb72ac9070484a7e3bd987e24
signaturelock-open Commit is signed but in an unrecognized format.

MachO: apply default header padding for codesign

When no headerpad_size parameter is passed, Zig doesn't reserve enough space for a codesign signature. Signing the binary corrupts the first bytes of __text, causing it to crash. The crash only affects x86_64 since aarch64 binaries are signed by the linker by default, so a new signature just replaces the existing one. This is a regression introduced by 7588eeccea on 2024-01-10. The fix restores the behavior prior to the regression by applying the default value. Fixes #31428.

1 files changed, 2 insertions(+), 1 deletions(-)

src/link/MachO/load_commands.zig+2-1
...@@ -164,7 +164,8 @@ pub fn calcLoadCommandsSizeObject(macho_file: *MachO) u32 {...@@ -164,7 +164,8 @@ pub fn calcLoadCommandsSizeObject(macho_file: *MachO) u32 {
164}164}
165165
166pub fn calcMinHeaderPadSize(macho_file: *MachO) !u32 {166pub fn calcMinHeaderPadSize(macho_file: *MachO) !u32 {
167 var padding: u32 = (try calcLoadCommandsSize(macho_file, false)) + (macho_file.headerpad_size orelse 0);167 var padding: u32 = (try calcLoadCommandsSize(macho_file, false)) +
168 (macho_file.headerpad_size orelse MachO.default_headerpad_size);
168 log.debug("minimum requested headerpad size 0x{x}", .{padding + @sizeOf(macho.mach_header_64)});169 log.debug("minimum requested headerpad size 0x{x}", .{padding + @sizeOf(macho.mach_header_64)});
169170
170 if (macho_file.headerpad_max_install_names) {171 if (macho_file.headerpad_max_install_names) {