oven-sh/bun · error · bun_exe_format::pe::Error
InsufficientHeaderSpace
Error message
InsufficientHeaderSpace
What it means
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.
Source
Thrown at src/exe_format/pe.rs:25
// New error types for PE manipulation
#[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 executablesView on GitHub (pinned to 8c5296ac45)
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.
Defensive patterns
Strategy: fallback
Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Related errors
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/61c6d26b6012ae5a.
Report an issue: GitHub.