{"record":{"id":"9e5bebc381f2caef","repo":"Pumpkin-MC/Pumpkin","slug":"nbt-read-error","errorCode":null,"errorMessage":"Nbt read error","messagePattern":"Nbt read error","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/bedrock/network_item.rs","lineNumber":609,"sourceCode":"    }\n    Ok(values)\n}\n\nfn read_user_data(\n    user_data: Vec<u8>,\n    is_shield: bool,\n) -> Result<(Nbt, Vec<String>, Vec<String>, i64), Error> {\n    if user_data.is_empty() {\n        return Ok((Nbt::default(), Vec::new(), Vec::new(), 0));\n    }\n\n    let mut cursor = std::io::Cursor::new(user_data);\n    let nbt_version = i16::read(&mut cursor)?;\n    let nbt_data = if nbt_version == -1 {\n        let _version = i8::read(&mut cursor)?;\n        let mut nbt_reader = NbtReadHelperBedrock::new(&mut cursor);\n        Nbt::read(&mut nbt_reader)\n            .map_err(|error| Error::new(std::io::ErrorKind::InvalidData, error))?\n    } else {\n        Nbt::default()\n    };\n    let place_on_blocks = read_user_data_strings(&mut cursor)?;\n    let destroy_blocks = read_user_data_strings(&mut cursor)?;\n    let shield_blocking_tick = if is_shield {\n        i64::read(&mut cursor)?\n    } else {\n        0\n    };\n    Ok((\n        nbt_data,\n        place_on_blocks,\n        destroy_blocks,\n        shield_blocking_tick,\n    ))\n}\n","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/bedrock/network_item.rs#L591-L627","documentation":"Thrown when parsing the NBT payload embedded in an item's user data fails. For version -1 user data the library reads a version byte and then Nbt::read via NbtReadHelperBedrock; any NBT parse error (bad tag, truncated data, unsupported version) is mapped to this InvalidData error.","triggerScenarios":"Triggered in read_user_data when nbt_version == -1 and Nbt::read returns an error: malformed NBT tags, truncated compound data, or an unsupported NBT version byte.","commonSituations":"Third-party clients/tools producing non-standard NBT, corrupted packets, protocol version mismatch causing NBT version negotiation differences, network truncation of the item payload.","solutions":["Verify client and server Bedrock protocol versions match (NBT encoding changed between versions).","Validate that the item's serialized NBT is well-formed using an NBT debugger on the sender side.","Check that the full packet was received; truncated user data leads to NBT read failures.","If a custom tool generates the item data, confirm it emits network little-endian NBT compatible with NbtReadHelperBedrock."],"exampleFix":"// before: writing disk-format NBT into the packet\nlet nbt = Nbt::write_disk_format(&value);\n// after\nlet nbt = Nbt::write_network_bedrock(&value); // network little-endian, headerless","handlingStrategy":"try-catch","validationCode":"fn nbt_version_is_supported(version: i16) -> bool {\n    version == -1 // only -1 signals an embedded NBT payload; others default\n}","typeGuard":null,"tryCatchPattern":"match read_user_data(&mut cursor, is_shield) {\n    Err(e) if e.to_string().contains(\"Nbt read error\") => {\n        log::warn!(\"malformed NBT in item user data: {e}; rejecting item\");\n        // fall back to a default item or disconnect the peer\n    }\n    other => other?,\n}","preventionTips":["Use the correct network (little-endian) NBT encoding for Bedrock packets","Ensure the full packet payload arrives before parsing (check frame length)","Test round-trip serialization of item NBT between your client version and server"],"tags":["bedrock","nbt","deserialization","protocol"],"backgroundTag":"invalid-argument-format","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"}