Pumpkin-MC/Pumpkin · error · Error

Failed to decode varlong - value too large

Error message

Failed to decode varlong - value too large

What it means

NBT decode guard for Bedrock variable-length longs: a VarLong continued past its maximum encoded size (10 bytes) and could not be decoded. Fires on the same kind of input as VarIntTooLarge but for 64-bit fields — a corrupted or misaligned varlong in the Bedrock NBT stream.

Solutions

  1. Reject the containing packet or NBT blob
  2. Limit varlong reads to the maximum encoded length
  3. Log the oversized varlong at debug level
Defensive patterns

Strategy: try-catch

Validate before calling

fn varlong_len_ok(bytes: &[u8]) -> bool { bytes.iter().take(10).position(|b| b & 0x80 == 0).is_some() }

Try / catch

if let Err(Error::VarLongTooLarge) = result { mark_source_corrupt(); }

Prevention

When it happens

Trigger: Reading Bedrock NBT where a varlong has its high continuation bit set past the 10-byte maximum.

Common situations: Corrupted Bedrock world data, buffer misalignment when reading embedded NBT, or mixing varint/varlong decoders across NBT variants.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09). Data as JSON: /api/errors/730e6792e69c9c10. Report an issue: GitHub.

Appendix: source

Thrown at crates/pumpkin-nbt/src/lib.rs:104

    #[error("Serde error: {0}")]
    SerdeError(String),
    /// The requested Rust type has no NBT representation.
    #[error("NBT doesn't support this type: {0}")]
    UnsupportedType(String),
    /// The underlying reader or writer returned an I/O error.
    #[error("NBT reading was cut short: {0}")]
    Incomplete(io::Error),
    /// A list or array declared a negative element count.
    #[error("Negative list length: {0}")]
    NegativeLength(i32),
    /// A string, list, or array exceeded the supported length.
    #[error("Length too large: {0}")]
    LargeLength(usize),
    /// A Bedrock variable-length integer exceeded its maximum encoded size.
    #[error("Failed to decode varint - value too large")]
    VarIntTooLarge,
    /// A Bedrock variable-length long exceeded its maximum encoded size.
    #[error("Failed to decode varlong - value too large")]
    VarLongTooLarge,
    /// NBT nesting depth exceeded the maximum allowed limit.
    #[error("NBT depth exceeded maximum allowed limit")]
    MaxDepthExceeded,
    /// A list tag specified an invalid element tag type.
    #[error("Invalid element tag type for list: {0}")]
    InvalidListTag(u8),
}

/// A complete NBT document containing a named root compound.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Nbt {
    /// Name stored alongside the root compound.
    pub name: String,
    /// Root compound containing the document's tags.
    pub root_tag: NbtCompound,
}

View on GitHub (pinned to 8d4639e25a)