{"record":{"id":"12a5b0ad70e8e9db","repo":"oven-sh/bun","slug":"sectionexists","errorCode":null,"errorMessage":"SectionExists","messagePattern":"SectionExists","errorType":"console","errorClass":"bun_exe_format::pe::Error","httpStatus":null,"severity":"error","filePath":"src/exe_format/pe.rs","lineNumber":29,"sourceCode":"    #[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}\n\n/// Windows PE Binary manipulation for codesigning standalone executables\npub struct PEFile {\n    pub(crate) data: Vec<u8>,\n    // Store offsets instead of pointers to avoid invalidation after resize\n    pub(crate) pe_header_offset: usize,","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/exe_format/pe.rs#L11-L47","documentation":"add_bun_section found an existing section named exactly '.bun' in the section table (src/exe_format/pe.rs:481-485) and refuses to add a second one. A .bun section means the base executable is itself already a Bun `--compile` output with an embedded module graph; layering another graph would leave two conflicting payloads.","triggerScenarios":"Using a previously produced `bun build --compile` executable as the base for another `--compile` build (re-compiling a compiled binary), or pointing `--base`/the cache at an already-injected standalone exe.","commonSituations":"Teams trying to 're-compile' or 'update' a shipped standalone exe by feeding it back to bun build; build pipelines that accidentally copy the previous build's output into the input path; using a stale compile cache entry that contains an injected binary.","solutions":["Compile from the pristine Bun executable plus your entrypoint, never from a previously compiled standalone exe.","Separate build input/output directories so a previous build's .exe can never be picked up as the base.","Clear BUN_COMPILE_CACHE if it may hold an injected binary.","If you need to update an embedded app, rebuild from source with `bun build --compile` again rather than re-patching the old artifact."],"exampleFix":"# before: re-compiling an already-compiled exe\nbun build app.ts --compile --outfile app.exe   # app.exe later reused as base\nbun build app.ts --compile --base app.exe --outfile app2.exe  # SectionExists\n# after: always base on the stock runtime\nbun build app.ts --compile --outfile app2.exe","handlingStrategy":"validation","validationCode":"const bytes = await Bun.file('base.exe').arrayBuffer();\nconst dv = new DataView(bytes);\nconst peOff = dv.getUint32(0x3c, true);\nconst numSections = dv.getUint16(peOff + 6, true);\nconst optSize = dv.getUint16(peOff + 20, true);\nconst table = peOff + 24 + optSize;\nfor (let i = 0; i < numSections; i++) {\n  const name = new Uint8Array(bytes, table + i * 40, 8);\n  if (String.fromCharCode(...name).startsWith('.bun')) throw new Error('base already contains a .bun section; use a pristine exe');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never feed a previously compiled standalone exe back as the base","Make CI copy the pristine base from a checksummed artifact store each build","Name compiled outputs distinctly (app-standalone.exe) so they can't be mistaken for bases"],"tags":["windows","pe","compile","idempotency","standalone"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}