{"record":{"id":"4d907fc630fbfb49","repo":"Pumpkin-MC/Pumpkin","slug":"failed-to-decode-varint-value-too-large","errorCode":null,"errorMessage":"Failed to decode varint - value too large","messagePattern":"Failed to decode varint - value too large","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/pumpkin-nbt/src/lib.rs","lineNumber":101,"sourceCode":"    #[error(\"Failed to UTF-8 Decode\")]\n    Utf8DecodingError,\n    /// Serde reported an invalid value or serializer state.\n    #[error(\"Serde error: {0}\")]\n    SerdeError(String),\n    /// The requested Rust type has no NBT representation.\n    #[error(\"NBT doesn't support this type: {0}\")]\n    UnsupportedType(String),\n    /// The underlying reader or writer returned an I/O error.\n    #[error(\"NBT reading was cut short: {0}\")]\n    Incomplete(io::Error),\n    /// A list or array declared a negative element count.\n    #[error(\"Negative list length: {0}\")]\n    NegativeLength(i32),\n    /// A string, list, or array exceeded the supported length.\n    #[error(\"Length too large: {0}\")]\n    LargeLength(usize),\n    /// A Bedrock variable-length integer exceeded its maximum encoded size.\n    #[error(\"Failed to decode varint - value too large\")]\n    VarIntTooLarge,\n    /// A Bedrock variable-length long exceeded its maximum encoded size.\n    #[error(\"Failed to decode varlong - value too large\")]\n    VarLongTooLarge,\n    /// NBT nesting depth exceeded the maximum allowed limit.\n    #[error(\"NBT depth exceeded maximum allowed limit\")]\n    MaxDepthExceeded,\n    /// A list tag specified an invalid element tag type.\n    #[error(\"Invalid element tag type for list: {0}\")]\n    InvalidListTag(u8),\n}\n\n/// A complete NBT document containing a named root compound.\n#[derive(Clone, Debug, Default, PartialEq)]\npub struct Nbt {\n    /// Name stored alongside the root compound.\n    pub name: String,\n    /// Root compound containing the document's tags.","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-nbt/src/lib.rs#L83-L119","documentation":"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.","triggerScenarios":"Reading Bedrock-format NBT where a varint never terminates within its maximum byte limit (e.g. continuation bits set past the 5-byte cap).","commonSituations":"Parsing corrupted Bedrock level data, desynced buffer offsets when reading NBT embedded in packets, or feeding Java-format NBT to the Bedrock reader.","solutions":["Reject the containing packet as invalid data","Cap varint reads to the maximum encoded length","Log the oversized varint at debug level"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"fn varint_len_ok(bytes: &[u8]) -> bool { bytes.iter().take(5).position(|b| b & 0x80 == 0).is_some() }","typeGuard":null,"tryCatchPattern":"if let Err(Error::VarIntTooLarge) = result { mark_source_corrupt(); }","preventionTips":["Keep buffer cursors aligned when parsing embedded NBT","Match the decoder variant to the encoder (Bedrock varint vs Java)","Fuzz-test parsers against malformed varints"],"tags":["nbt","varint","bedrock","deserialization"],"backgroundTag":"value-out-of-range","analyzedSha":"8d4639e25a57c15e47448ec327c780d41bbf2356","analyzedAt":"2026-09-09T15:32:22.916Z","contentChangedAt":"2026-09-09T15:32:22.916Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}