From d295749e627521ea3f6a8b05d95ca725ec183b0f Mon Sep 17 00:00:00 2001 From: TheErsysEnding <70489198+TheErsysEnding@users.noreply.github.com> Date: Tue, 3 Nov 2026 14:56:13 +0100 Subject: [PATCH] fself: don't read before the ELF when .sceversion is missing elf_get_shstr_off() returns -1 when a section does not exist, and self_build_sceversion_header() then ran strlen() on elf_data - 1. ELFs built with the PSL1GHT rules have no .sceversion section, so this happened on every build. On Linux the stray read usually goes unnoticed and leaves a bogus offset and size in the fake SELF; on Apple Silicon macOS fself dies with SIGBUS, which stops "make" at the .self step. Leave section_idx, offset and str_size at zero when the section is absent. ELFs that do have the section produce the same output as before. Co-Authored-By: Claude Opus 5.5 --- tools/fself/source/self.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/fself/source/self.c b/tools/fself/source/self.c index 24fb9c31..eb4a6d22 100644 --- a/tools/fself/source/self.c +++ b/tools/fself/source/self.c @@ -301,9 +301,12 @@ void self_build_sceversion_header(SCEVERSION_INFO *info,const void *elf_data,uin info->unknown1 = 1; info->unknown2 = 1; info->size = sizeof(SCEVERSION_INFO); - info->section_idx = sce_idx; info->unknown4 = 1; info->unknown6 = 1; + /* no .sceversion section: sce_off is -1, and strlen would read before elf_data */ + if (sce_idx < 0) + return; + info->section_idx = sce_idx; info->offset = sce_off + elfOffset; info->str_size = strlen((char*)elf_data + sce_off); }