{"record":{"id":"049e66e10b905f1d","repo":"Pumpkin-MC/Pumpkin","slug":"item-string-too-long","errorCode":null,"errorMessage":"item string too long","messagePattern":"item string too long","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/bedrock/network_item.rs","lineNumber":559,"sourceCode":"        let mut extra_data = vec![0u8; extra_data_len];\n        buf.read_exact(&mut extra_data)?;\n\n        Ok(Self {\n            id,\n            count,\n            aux_value,\n            block_runtime_id,\n            extra_data,\n        })\n    }\n}\n\nfn write_user_data_strings<W: Write>(writer: &mut W, values: &[String]) -> Result<(), Error> {\n    (values.len() as i32).write(writer)?;\n    for value in values {\n        let bytes = value.as_bytes();\n        let len = u16::try_from(bytes.len())\n            .map_err(|_| Error::new(std::io::ErrorKind::InvalidInput, \"item string too long\"))?;\n        writer.write_all(&len.to_be_bytes())?;\n        writer.write_all(bytes)?;\n    }\n    Ok(())\n}\n\nfn read_user_data_strings<R: Read>(reader: &mut R) -> Result<Vec<String>, Error> {\n    let len = i32::read(reader)?;\n    if !(0..=1024).contains(&len) {\n        return Err(Error::new(\n            std::io::ErrorKind::InvalidData,\n            \"item string array length out of bounds\",\n        ));\n    }\n    let mut values = Vec::with_capacity((len as usize).min(32));\n    for _ in 0..len {\n        let mut length = [0; 2];\n        reader.read_exact(&mut length)?;","sourceCodeStart":541,"sourceCodeEnd":577,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/bedrock/network_item.rs#L541-L577","documentation":"Raised by write_user_data_strings when a user-data string's UTF-8 encoding exceeds u16::MAX bytes (65535). The Bedrock format prefixes each string with a u16 big-endian length, so longer strings cannot be encoded; the writer converts the try_from failure into an InvalidInput error.","triggerScenarios":"Serializing item user data (e.g., custom item name, lore strings) where any string's byte length > 65535 and calling the packet write path.","commonSituations":"Plugins setting absurdly long custom item names/lore from user input; concatenating text without a length check; multi-byte UTF-8 (emoji, CJK) pushing a string past the byte cap even when char count seems small.","solutions":["Truncate or reject strings longer than 65535 bytes before building the packet.","Validate at the plugin API boundary where players can submit text (names, lore).","Measure byte length (value.len()), not character count — multi-byte characters count more.","Split oversized text into multiple entries if the format allows."],"exampleFix":"// before\nvalues.push(user_supplied_name); // may exceed 65535 bytes\n// after\nconst MAX: usize = u16::MAX as usize;\nvalues.push(if user_supplied_name.len() > MAX {\n    truncate_at_char_boundary(&user_supplied_name, MAX)\n} else { user_supplied_name });","handlingStrategy":"validation","validationCode":"fn string_fits_u16(s: &str) -> bool { s.len() <= u16::MAX as usize }\n// check before pushing into user data strings\nassert!(string_fits_u16(&name), \"item string too long\");","typeGuard":"fn truncate_utf16_safe(s: &str, max_bytes: usize) -> String {\n    if s.len() <= max_bytes { return s.to_string(); }\n    let mut end = max_bytes;\n    while !s.is_char_boundary(end) { end -= 1; }\n    s[..end].to_string()\n}","tryCatchPattern":"packet.write(&mut writer).map_err(|e| {\n    if e.to_string() == \"item string too long\" {\n        log::error!(\"user-data string exceeded 65535 bytes\");\n    }\n    e\n})?;","preventionTips":["Validate player-supplied item names/lore at the plugin API boundary.","Check byte length (str::len), not character count — UTF-8 multi-byte chars count more.","Truncate on a char boundary to avoid corrupting text."],"tags":["protocol","bedrock","serialization","string-length"],"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"}