Pumpkin-MC/Pumpkin · error · Error

Failed to decode varint - value too large

Error message

Failed to decode varint - value too large

What it means

NBT decode guard for Bedrock variable-length integers: a VarInt in the stream kept setting continuation bits past its maximum encoded size (5 bytes), so decoding aborted. The offending input is a length/varint field inside the NBT payload whose encoding runs longer than allowed — a sign of corrupted or truncated/misaligned data rather than a legitimate value.

Solutions

  1. Reject the containing packet as invalid data
  2. Cap varint reads to the maximum encoded length
  3. Log the oversized varint at debug level
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

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

Prevention

When it happens

Trigger: Reading Bedrock-format NBT where a varint never terminates within its maximum byte limit (e.g. continuation bits set past the 5-byte cap).

Common situations: Parsing corrupted Bedrock level data, desynced buffer offsets when reading NBT embedded in packets, or feeding Java-format NBT to the Bedrock reader.

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/4d907fc630fbfb49. Report an issue: GitHub.

Appendix: source

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

    #[error("Failed to UTF-8 Decode")]
    Utf8DecodingError,
    /// Serde reported an invalid value or serializer state.
    #[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.

View on GitHub (pinned to 8d4639e25a)