{"record":{"id":"0f02b1ea88e32aa8","repo":"oven-sh/bun","slug":"toomanysections","errorCode":null,"errorMessage":"TooManySections","messagePattern":"TooManySections","errorType":"console","errorClass":"bun_exe_format::pe::Error","httpStatus":null,"severity":"error","filePath":"src/exe_format/pe.rs","lineNumber":27,"sourceCode":"#[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\npub struct PEFile {\n    pub(crate) data: Vec<u8>,","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/exe_format/pe.rs#L9-L45","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use the stock Bun executable as the compile base; it has far fewer than 96 sections.","Rebuild/normalize the custom base with fewer sections (merge function sections, drop packer stubs) so the count is comfortably below 96.","Run `dumpbin /headers base.exe | grep -A1 'number of sections'` (or a PE editor) to confirm the count before compiling.","If the count looks absurd (e.g. 65535), the base is corrupted — replace it."],"exampleFix":null,"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); // COFF NumberOfSections at +2 sig +6\nif (numSections > 90) throw new Error(`base has ${numSections} sections; too close to the 96 limit`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Count sections in the base before compiling (dumpbin /headers or the snippet above)","Don't use obfuscator/packer output as a compile base","Rebuild custom bases with merged sections (-ffunction-sections off, /MERGE)"],"tags":["windows","pe","compile","sections","limits"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}