{"record":{"id":"204f010986dbfeb3","repo":"jdx/mise","slug":"malformed-fat-header-in","errorCode":null,"errorMessage":"malformed fat header in {}","messagePattern":"malformed fat header in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/macho.rs","lineNumber":186,"sourceCode":"    Ok(true)\n}\n\n/// Patch load-command path strings in a Mach-O file (thin or fat).\n/// Returns whether anything changed.\npub(super) fn patch(content: &mut [u8], replacements: &[Replacement], path: &Path) -> Result<bool> {\n    if content.len() < 8 {\n        return Ok(false);\n    }\n    let be_magic = u32::from_be_bytes(content[..4].try_into().unwrap());\n    if be_magic == FAT_MAGIC_BE {\n        let nfat = u32::from_be_bytes(content[4..8].try_into().unwrap()) as usize;\n        let mut changed = false;\n        // collect slice ranges first (fat headers are big-endian)\n        let mut ranges = vec![];\n        for i in 0..nfat {\n            let entry = 8 + i * 20;\n            if entry + 20 > content.len() {\n                bail!(\"malformed fat header in {}\", path.display());\n            }\n            let offset =\n                u32::from_be_bytes(content[entry + 8..entry + 12].try_into().unwrap()) as usize;\n            let size =\n                u32::from_be_bytes(content[entry + 12..entry + 16].try_into().unwrap()) as usize;\n            if offset + size > content.len() {\n                bail!(\"malformed fat arch in {}\", path.display());\n            }\n            ranges.push(offset..offset + size);\n        }\n        for range in ranges {\n            changed |= patch_slice(&mut content[range], replacements, path)?;\n        }\n        Ok(changed)\n    } else {\n        patch_slice(content, replacements, path)\n    }\n}","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/brew/macho.rs#L168-L204","documentation":"Thrown when a fat (universal) Mach-O header's arch entry table extends past the end of the file: the 20-byte fat_arch entry at index i would be truncated. The big-endian fat header parse refuses to continue with corrupt or truncated archive tables.","triggerScenarios":"patch iterates nfat_arch entries; `entry + 20 > content.len()` bails. Caused by truncated universal binaries, corrupt nfat_arch counts, or a file whose magic matched the fat magic but whose body was cut short.","commonSituations":"Interrupted downloads of universal bottles; files concatenated or split incorrectly; patching fat frameworks that were partially copied; disk corruption.","solutions":["Re-download/reinstall the universal binary (`brew reinstall <formula>`).","Verify with `lipo -info <binary>` that the fat header parses.","Check the file size against the bottle manifest to detect truncation.","Patch each thin slice individually with `lipo -thin` if the fat table itself is suspect."],"exampleFix":"// before\npatch(&fat_binary, &replacements)?;\n// after: validate first\nlet out = Command::new(\"lipo\").args([\"-info\"]).arg(&fat_binary).output()?;\nif !out.status.success() { anyhow::bail!(\"corrupt fat header in {}\", fat_binary.display()); }\npatch(&fat_binary, &replacements)?;","handlingStrategy":"validation","validationCode":"fn fat_header_fits(content: &[u8]) -> bool {\n    if content.len() < 8 { return false; }\n    let nfat = u32::from_be_bytes(content[4..8].try_into().unwrap()) as usize;\n    8 + nfat * 20 <= content.len()\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = patch(&fat, &repl) {\n    if format!(\"{e}\").contains(\"malformed fat header\") {\n        eprintln!(\"{} is not a valid universal binary; reinstall\", fat.display());\n    }\n}","preventionTips":["Verify with `lipo -info` before patching universal binaries.","Check downloaded artifact sizes against manifests.","Never concatenate or trim fat binaries manually."],"tags":["macos","fat-binary","corrupt-file"],"backgroundTag":"schema-validation-failed","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}