{"record":{"id":"b9c28671eba21db4","repo":"oven-sh/bun","slug":"unsupportedpeformat","errorCode":null,"errorMessage":"UnsupportedPEFormat","messagePattern":"UnsupportedPEFormat","errorType":"console","errorClass":"bun_exe_format::pe::Error","httpStatus":null,"severity":"error","filePath":"src/exe_format/pe.rs","lineNumber":23,"sourceCode":"use core::ptr;\nuse core::slice;\n\n// New error types for PE manipulation\n#[derive(thiserror::Error, strum::IntoStaticStr, Debug, Copy, Clone, Eq, PartialEq)]\npub enum Error {\n    #[error(\"OutOfBounds\")]\n    OutOfBounds,\n    #[error(\"BadAlignment\")]\n    BadAlignment,\n    #[error(\"Overflow\")]\n    Overflow,\n    #[error(\"InvalidPEFile\")]\n    InvalidPEFile,\n    #[error(\"InvalidDOSSignature\")]\n    InvalidDOSSignature,\n    #[error(\"InvalidPESignature\")]\n    InvalidPESignature,\n    #[error(\"UnsupportedPEFormat\")]\n    UnsupportedPEFormat,\n    #[error(\"InsufficientHeaderSpace\")]\n    InsufficientHeaderSpace,\n    #[error(\"TooManySections\")]\n    TooManySections,\n    #[error(\"SectionExists\")]\n    SectionExists,\n    #[error(\"InputIsSigned\")]\n    InputIsSigned,\n    #[error(\"InvalidSecurityDirectory\")]\n    InvalidSecurityDirectory,\n    #[error(\"SecurityDirInsideImage\")]\n    SecurityDirInsideImage,\n    #[error(\"UnexpectedOverlayPresent\")]\n    UnexpectedOverlayPresent,\n    #[error(\"InsufficientSpace\")]\n    InsufficientSpace,\n}","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/exe_format/pe.rs#L5-L41","documentation":"The optional header magic is not 0x020B (PE32+/64-bit), so Bun refuses the image (src/exe_format/pe.rs:291-293). Bun's .bun-section injector only understands 64-bit PE images because the injected section layout (OptionalHeader64, 16 data directories) assumes PE32+. A 32-bit PE has magic 0x010B and a different optional-header shape, so parsing on would be unsound.","triggerScenarios":"`bun build --compile` targeting Windows with a 32-bit (i386) base executable, e.g. a manually supplied 32-bit bun build, an old 32-bit launcher used as the base, or any PE32 image. Thrown when optional_header.magic != 0x020B in PEFile::init.","commonSituations":"Mixing architectures: building with a windows-x64 target while the base exe on PATH or in the cache is 32-bit; legacy toolchains producing PE32 wrappers; using a 32-bit stub loader as the custom base for Bun compilation.","solutions":["Use the 64-bit Bun executable as the base (bun-windows-x64 / bun-windows-aarch64); Bun ships only PE32+ binaries.","Verify the base with `file base.exe` — it must report 'PE32+ executable', not 'PE32 executable'.","Clear stale build caches (BUN_COMPILE_CACHE) that may hold a 32-bit base from earlier experiments.","If you must target 32-bit Windows, that is unsupported by `bun build --compile`; ship the 64-bit binary instead."],"exampleFix":"# before\nfile base.exe   # 'PE32 executable (console) Intel 80386'\nbun build app.ts --compile --target=windows-x64 --base base.exe\n# after: fetch the matching 64-bit base\nfile bun.exe    # 'PE32+ executable (console) x86-64'\nbun build app.ts --compile --target=windows-x64","handlingStrategy":"validation","validationCode":"const bytes = await Bun.file('base.exe').arrayBuffer();\nconst dv = new DataView(bytes);\nconst peOff = dv.getUint32(0x3c, true);\nconst optMagicOff = peOff + 4 + 20; // signature + COFF header\nif (dv.byteLength < optMagicOff + 2 || dv.getUint16(optMagicOff, true) !== 0x020b) {\n  throw new Error('base.exe is not PE32+ (64-bit) — get the x64/arm64 Bun build');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `file base.exe` and require 'PE32+' in CI before compile steps","Only download bases from official Bun release artifacts for the exact target arch","Automate base selection from --target so humans never hand-pick mismatched exes"],"tags":["windows","pe","compile","architecture","standalone"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}