{"record":{"id":"61c6d26b6012ae5a","repo":"oven-sh/bun","slug":"insufficientheaderspace","errorCode":null,"errorMessage":"InsufficientHeaderSpace","messagePattern":"InsufficientHeaderSpace","errorType":"console","errorClass":"bun_exe_format::pe::Error","httpStatus":null,"severity":"error","filePath":"src/exe_format/pe.rs","lineNumber":25,"sourceCode":"\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}\n\n/// Windows PE Binary manipulation for codesigning standalone executables","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/exe_format/pe.rs#L7-L43","documentation":"Adding the .bun section header would push the section header table past the start of the first section's raw data (src/exe_format/pe.rs:512-514 and the second guard at :564-566). PE requires all headers to fit in the slack before the first section's file data; if the base executable's headers end almost exactly at first_raw, there is no room for one more 40-byte section header.","triggerScenarios":"`bun build --compile --target=windows` where the base PE has its first section's PointerToRawData tightly abutting the section header table (no FileAlignment-sized slack). add_bun_section computes new_size_of_headers = align_up(headers_end, file_alignment) and errors when it exceeds first_raw.","commonSituations":"Using a hand-crafted or post-processed base executable that was relinked with minimal header space; packers (UPX and similar) that rewrite the PE with packed headers; a base exe whose headers were already extended by another embedding tool.","solutions":["Use the stock Bun executable for the target as the --compile base — its header slack is validated for .bun injection.","If a custom base is required, relink it with a larger header region (e.g. /FILEALIGN:512 plus extra section-table room, or /HEADERSIZE-style linker options) so at least one more 40-byte section header fits before the first section.","Unpack or un-UPX the base executable before using it as the compile base.","Check the geometry with `dumpbin /headers base.exe` (SizeOfHeaders vs first section PointerToRawData) to confirm the fix."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer the stock Bun executable as the compile base — its header slack is validated","Avoid packed/obfuscated bases (UPX etc.) that eliminate header slack","When building custom bases, leave at least one section-header's worth (40B, aligned to FileAlignment) of space after the section table"],"tags":["windows","pe","compile","sections","standalone"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}