{"record":{"id":"6396ecc42db718ff","repo":"Pumpkin-MC/Pumpkin","slug":"negative-list-length-0","errorCode":null,"errorMessage":"Negative list length: {0}","messagePattern":"Negative list length: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/pumpkin-nbt/src/lib.rs","lineNumber":95,"sourceCode":"    #[error(\"Encountered an unknown NBT tag id: {0}.\")]\n    UnknownTagId(u8),\n    /// A Java CESU-8 string could not be decoded.\n    #[error(\"Failed to Cesu 8 Decode\")]\n    Cesu8DecodingError,\n    /// A string could not be decoded as UTF-8.\n    #[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","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-nbt/src/lib.rs#L77-L113","documentation":"Error::NegativeLength(i32) is raised when a list or byte/int/long array tag declares a negative element count while decoding. NBT lengths are i32 but must be >= 0; a negative value cannot describe a real array. The library throws it to prevent absurd allocations and to signal corrupt or maliciously crafted data. The i32 payload is the declared (negative) length.","triggerScenarios":"Decoding NBT whose list/array length field is negative (corrupt file or crafted packet); stream desynchronization so a payload byte is read as part of the length, flipping its sign; reading Java big-endian data with a little-endian reader (or vice versa).","commonSituations":"Malicious client/server packets designed to trigger allocation bugs; corrupted world files; endianness mix-ups between Java and Bedrock variants; offset errors after a prior misparsed tag.","solutions":["Treat the input as corrupt: reject the packet/file and log the declared length and offset for diagnosis.","Check endianness — Bedrock NBT is little-endian; reading it big-endian corrupts length fields.","Verify stream alignment from the start of the document; a single earlier misread cascades into the length field.","If the source is untrusted, keep the crate's bounds in mind and never bypass them with your own length handling."],"exampleFix":"// before: reading Bedrock data with the Java (big-endian) reader\nlet nbt = Nbt::from_reader(&mut bedrock_data)?;\n// after\nlet nbt = Nbt::from_reader_bedrock(&mut bedrock_data)?;","handlingStrategy":"validation","validationCode":"// Rust: reject untrusted NBT unless the source is verified\nfn looks_trusted(source: &DataSource) -> bool { source.is_authenticated() }","typeGuard":null,"tryCatchPattern":"match Nbt::from_reader(&mut reader) {\n    Err(pumpkin_nbt::Error::NegativeLength(n)) => eprintln!(\"corrupt/crafted data: len {n}\"),\n    Err(e) => return Err(e.into()),\n    Ok(nbt) => nbt,\n}","preventionTips":["Never feed untrusted network data to the wrong-dialect decoder (endianness mix-ups corrupt length fields)","Validate stream alignment from the document start so length fields are read correctly","Treat negative lengths as a corruption/attack signal and drop the connection or file"],"tags":["minecraft","nbt","decoding","corrupt-data"],"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-16T04:17:20.429Z"}