jdx/mise · error
malformed load command in
Error message
malformed load command in {} What it means
Thrown when an individual load command inside the table is invalid: either its cmdsize is smaller than the minimum 8 bytes or the command extends past lc_end. This is a finer-grained check than the table-level error and indicates the specific command at the current offset is corrupt.
Solutions
- Reinstall the formula to replace the corrupt binary.
- Identify the offending command with `otool -l` and restore the binary from a known-good bottle.
- Have the patcher report the offset and cmd value for diagnosis before failing.
- Skip non-essential patching for binaries with anomalous load commands.
Example fix
// before: blind patch
brew_patch(&path)?;
// after: verify parseability first
let out = Command::new("otool").args(["-l"]).arg(&path).output()?;
if !out.status.success() { anyhow::bail!("bad load command in {}", path.display()); }
brew_patch(&path)?; Defensive patterns
Strategy: validation
Validate before calling
fn has_min_table(content: &[u8]) -> bool {
content.len() >= 32
&& u32::from_le_bytes(content[16..20].try_into().unwrap()) > 0
&& u32::from_le_bytes(content[20..24].try_into().unwrap()) as usize + 32 <= content.len()
} Try / catch
if let Err(e) = brew_patch(&path) {
if format!("{e}").contains("malformed load command in") {
// fall back to reinstall
let _ = Command::new("brew").args(["reinstall", formula]).status();
}
} Prevention
- Reinstall rather than patching binaries flagged by otool/codesign.
- Avoid third-party post-install strippers on bottles.
- Snapshot binaries before rewriting so failures are recoverable.
When it happens
Trigger: patch_slice reads cmd and cmdsize at the current offset; `cmdsize < 8 || off + cmdsize > lc_end` triggers the bail. Occurs with binaries whose load commands were truncated, misaligned, or produced by a broken linker/post-processor.
Common situations: Binaries processed by outdated or buggy strip/install_name_tool-like utilities; corrupted bottles; patching binaries built with unusual linkers; slices misaligned by earlier incorrect parsing.
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.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- malformed load command table in
- malformed Mach-O in
- malformed fat arch in
- malformed fat header in
- another process is installing the mise notification helper
AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17).
Data as JSON: /api/errors/f61b50ccda0572a7.
Report an issue: GitHub.
Appendix: source
Thrown at src/system/packages/brew/macho.rs:90
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);
}
}
}
off += cmdsize;
}
}View on GitHub (pinned to 533346cc37)