oven-sh/bun · error · Error

BadAlignment

Error message

BadAlignment

What it means

PE error variant: a computed layout does not satisfy the alignment invariants Windows PE requires (file alignment typically 512 bytes, section alignment rules). The writer refuses to emit misaligned offsets because the resulting image would not load.

Solutions

  1. Ensure the target was linked with standard /FILEALIGN and /SECTIONALIGN settings
  2. Fix the alignment computation (align_up usage) in pe.rs for the field being written
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/exe_format/pe.rs:13 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/5ebecc9f6830cd54. Report an issue: GitHub.

Appendix: source

Thrown at src/exe_format/pe.rs:13

// Windows PE sections use standard file alignment (typically 512 bytes)
// No special 16KB alignment needed like macOS code signing

use core::mem::{offset_of, size_of};
use core::ptr;
use core::slice;

// 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")]

View on GitHub (pinned to 8c5296ac45)