jdx/mise · error

malformed load command table in

Error message

malformed load command table in {}

What it means

Thrown during the validation pass over the Mach-O load-command table when a command header would start or extend beyond lc_end (the end of the command table). It means ncmds and sizeofcmds disagree — the table claims more commands than its declared size can hold.

Solutions

  1. Reinstall the formula to restore a pristine binary.
  2. Run `otool -l <binary>` to confirm the load-command table parses with standard tools before patching.
  3. Reject binaries whose ncmds/sizeofcmds are inconsistent instead of patching.
  4. Check whether another post-install step modified the binary before the patcher ran.

Example fix

// before
patch(&path, &replacements)?;
// after: sanity-check with otool first
if !Command::new("otool").args(["-l"]).arg(&path).status()?.success() {
    anyhow::bail!("{} has an unparseable load-command table; reinstall", path.display());
}
patch(&path, &replacements)?;
Defensive patterns

Strategy: validation

Validate before calling

fn table_consistent(content: &[u8]) -> bool {
    let ncmds = u32::from_le_bytes(content[16..20].try_into().unwrap()) as usize;
    let sizeofcmds = u32::from_le_bytes(content[20..24].try_into().unwrap()) as usize;
    32 + ncmds * 8 <= 32 + sizeofcmds
}

Try / catch

match patch(&path, &replacements) {
    Err(e) if e.to_string().contains("malformed load command") => {
        eprintln!("corrupt binary {}; reinstall formula", path.display());
    }
    other => other?,
}

Prevention

When it happens

Trigger: patch_slice iterates ncmds commands starting at HEADER_SIZE_64; if off + 8 > lc_end for any iteration it bails. Caused by corrupt headers where ncmds was incremented or sizeofcmds truncated, or a slice that matched the 64-bit magic check but is not a valid MH_MAGIC_64 image.

Common situations: Hand-edited or tool-mangled binaries; patching a file whose first 32 bytes coincidentally matched the magic check; partially overwritten binaries; wrong arch slice offsets inside fat binaries.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/55534a24e2636d0f. Report an issue: GitHub.

Appendix: source

Thrown at src/system/packages/brew/macho.rs:85

        // not a 64-bit LE Mach-O (32-bit or big-endian) — nothing modern on
        // arm64 macOS; leave it to the caller's generic byte-level pass
        return Ok(false);
    }
    let ncmds = u32_at(slice, 16) as usize;
    let sizeofcmds = u32_at(slice, 20) as usize;
    if HEADER_SIZE_64 + sizeofcmds > slice.len() {
        bail!("malformed Mach-O in {}", path.display());
    }

    // upper bound for growing the load-command table: the first byte of
    // section data (everything between sizeofcmds and there is padding)
    let lc_end = HEADER_SIZE_64 + sizeofcmds;
    let mut first_data = slice.len();
    {
        let mut off = HEADER_SIZE_64;
        for _ in 0..ncmds {
            if off + 8 > lc_end {
                bail!("malformed load command table in {}", path.display());
            }
            let cmd = u32_at(slice, off);
            let cmdsize = u32_at(slice, off + 4) as usize;
            if cmdsize < 8 || off + cmdsize > lc_end {
                bail!("malformed load command in {}", path.display());
            }
            if cmd == LC_SEGMENT_64 {
                let nsects = u32_at(slice, off + 64) as usize;
                for i in 0..nsects {
                    // struct section_64 is 80 bytes; offset field at +48
                    let sect = off + 72 + i * 80;
                    if sect + 80 > off + cmdsize {
                        break;
                    }
                    let file_off = u32_at(slice, sect + 48) as usize;
                    if file_off > 0 {
                        first_data = first_data.min(file_off);
                    }

View on GitHub (pinned to 533346cc37)