oven-sh/bun · error · MachoError

OffsetOutOfRange

Error message

OffsetOutOfRange

What it means

MachoError variant: a serialized offset/size read from the Mach-O points past the end of the file buffer. Usually the result of a malformed or truncated binary where a load command, blob index, or code-directory field references data that is not actually present.

Solutions

  1. Re-obtain or rebuild the executable — out-of-range offsets indicate truncation or corruption
  2. If the file is expected to be valid, dump its load commands (otool -l) to find which structure holds the bad offset and harden the parser
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/exe_format/macho.rs:20 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/891a6d344669bad5. Report an issue: GitHub.

Appendix: source

Thrown at src/exe_format/macho.rs:20

// `std.macho` types ported locally (see macho_types.rs).
use crate::align_up as align_size;
use crate::macho_types as macho;
use crate::macho_types::{BlobIndex, CodeDirectory, SuperBlob};
use crate::{read_struct, write_struct};

use bun_core::env_var::feature_flag;

const SEGNAME_BUN: [u8; 16] = *b"__BUN\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
const SECTNAME: [u8; 16] = *b"__bun\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";

#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error, strum::IntoStaticStr)]
pub enum MachoError {
    #[error("InvalidObject")]
    InvalidObject,
    #[error("MissingLinkeditSegment")]
    MissingLinkeditSegment,
    #[error("OffsetOutOfRange")]
    OffsetOutOfRange,
    #[error("OffsetOverflow")]
    OffsetOverflow,
    #[error("InvalidLinkeditOffset")]
    InvalidLinkeditOffset,
    #[error("OverlappingSegments")]
    OverlappingSegments,
    #[error("MissingRequiredSegment")]
    MissingRequiredSegment,
    #[error("OutOfMemory")]
    OutOfMemory,
}
bun_core::oom_from_alloc!(MachoError);

pub struct MachoFile {
    pub(crate) header: macho::mach_header_64,
    pub(crate) data: Vec<u8>,
    pub(crate) segment: macho::segment_command_64,

View on GitHub (pinned to 8c5296ac45)