oven-sh/bun · error · MachoError

OffsetOverflow

Error message

OffsetOverflow

What it means

MachoError variant: an arithmetic operation on offsets/sizes while rewriting the Mach-O overflowed (e.g. offset + length exceeding usize, or growth past the address space). It protects the writer from wrapping around and producing overlapping or negative ranges on implausible inputs.

Solutions

  1. Check the input binary for absurd header values (huge sizes) that cause the arithmetic to blow up
  2. Use checked arithmetic and clearer diagnostics at the computation site in macho.rs
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/exe_format/macho.rs:22 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/eab515a1d4c45e38. Report an issue: GitHub.

Appendix: source

Thrown at src/exe_format/macho.rs:22

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,
    pub(crate) section: macho::section_64,
}

View on GitHub (pinned to 8c5296ac45)