oven-sh/bun · error · bun_exe_format::pe::Error

TooManySections

Error message

TooManySections

What it means

The PE image declares more than 96 sections (PEFile::init, src/exe_format/pe.rs:309-311) or already has 96 sections when Bun tries to append the .bun section (src/exe_format/pe.rs:488-491). 96 is the classic PE COFF section-count limit the injector enforces; beyond it the section table cannot grow.

Source

Thrown at src/exe_format/pe.rs:27

#[derive(thiserror::Error, strum::IntoStaticStr, Debug, Copy, Clone, Eq, PartialEq)]
pub enum Error {
    #[error("OutOfBounds")]
    OutOfBounds,
    #[error("BadAlignment")]
    BadAlignment,
    #[error("Overflow")]
    Overflow,
    #[error("InvalidPEFile")]
    InvalidPEFile,
    #[error("InvalidDOSSignature")]
    InvalidDOSSignature,
    #[error("InvalidPESignature")]
    InvalidPESignature,
    #[error("UnsupportedPEFormat")]
    UnsupportedPEFormat,
    #[error("InsufficientHeaderSpace")]
    InsufficientHeaderSpace,
    #[error("TooManySections")]
    TooManySections,
    #[error("SectionExists")]
    SectionExists,
    #[error("InputIsSigned")]
    InputIsSigned,
    #[error("InvalidSecurityDirectory")]
    InvalidSecurityDirectory,
    #[error("SecurityDirInsideImage")]
    SecurityDirInsideImage,
    #[error("UnexpectedOverlayPresent")]
    UnexpectedOverlayPresent,
    #[error("InsufficientSpace")]
    InsufficientSpace,
}

/// Windows PE Binary manipulation for codesigning standalone executables
pub struct PEFile {
    pub(crate) data: Vec<u8>,

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Use the stock Bun executable as the compile base; it has far fewer than 96 sections.
  2. Rebuild/normalize the custom base with fewer sections (merge function sections, drop packer stubs) so the count is comfortably below 96.
  3. Run `dumpbin /headers base.exe | grep -A1 'number of sections'` (or a PE editor) to confirm the count before compiling.
  4. If the count looks absurd (e.g. 65535), the base is corrupted — replace it.
Defensive patterns

Strategy: validation

Validate before calling

const bytes = await Bun.file('base.exe').arrayBuffer();
const dv = new DataView(bytes);
const peOff = dv.getUint32(0x3c, true);
const numSections = dv.getUint16(peOff + 6, true); // COFF NumberOfSections at +2 sig +6
if (numSections > 90) throw new Error(`base has ${numSections} sections; too close to the 96 limit`);

Prevention

When it happens

Trigger: Compiling standalone for Windows with a base executable that already carries 96+ sections — typically produced by heavy obfuscators, multi-packers, or debug-info-stripped builds that split code into many tiny sections.

Common situations: Custom base executables processed by tools like Themida/VMProtect/UPX with many sections; Rust/C++ bases built with -ffunction-sections and custom linker scripts creating dozens of sections; malicious or corrupted PEs with a garbage NumberOfSections field.

Related errors


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