{"record":{"id":"861186be9182151d","repo":"Pumpkin-MC/Pumpkin","slug":"name-length-len-exceeds-max-collection-length-861186","errorCode":null,"errorMessage":"{name} length {len} exceeds {MAX_COLLECTION_LENGTH}","messagePattern":"(.+?) length (.+?) exceeds (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/bedrock/server/item_stack_request.rs","lineNumber":15,"sourceCode":"use std::io::{Error, ErrorKind, Read};\n\nuse crate::{\n    bedrock::network_item::FullContainerName,\n    codec::{var_int::VarInt, var_uint::VarUInt},\n    serial::{PacketRead, PacketWrite},\n};\nuse pumpkin_macros::packet;\n\nconst MAX_COLLECTION_LENGTH: u32 = 1024;\n\nfn collection_length<R: Read>(reader: &mut R, name: &str) -> Result<usize, Error> {\n    let len = VarUInt::read(reader)?.0;\n    if len > MAX_COLLECTION_LENGTH {\n        return Err(Error::new(\n            ErrorKind::InvalidData,\n            format!(\"{name} length {len} exceeds {MAX_COLLECTION_LENGTH}\"),\n        ));\n    }\n    Ok(len as usize)\n}\n\n#[derive(Debug, PacketRead, PacketWrite)]\npub struct ItemStackRequestSlotInfo {\n    pub container_name: FullContainerName,\n    pub slot_id: u8,\n    pub stack_id: i32,\n}\n\n#[derive(Debug)]\npub struct StackRequestItem {\n    pub identifier: Option<String>,\n    pub metadata_value: VarInt,","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/bedrock/server/item_stack_request.rs#L1-L33","documentation":"Thrown by collection_length in the Bedrock item-stack-request decoder when a collection length VarUInt read from the packet exceeds MAX_COLLECTION_LENGTH (1024). The library rejects it early instead of allocating a huge Vec from untrusted client data. It is an InvalidData io::Error, so the whole packet is discarded.","triggerScenarios":"A client sends an ItemStackRequest packet whose length-prefixed collection (e.g. request action list or container slots) declares more than 1024 entries; typically a malformed, fuzzed, or hostile packet, or a protocol-version mismatch where a field is misparsed as a length.","commonSituations":"Connecting with a Bedrock client whose protocol version does not match the server's, custom/modified clients, or proxy/fuzzer traffic injecting oversized length fields.","solutions":["Update the Bedrock client/server to matching protocol versions","Inspect the packet capture to see which collection declares the oversized length","If writing a test, cap generated collection lengths at 1024","If intentionally sending large payloads, raise MAX_COLLECTION_LENGTH in crates/pumpkin-protocol/src/bedrock/server/item_stack_request.rs"],"exampleFix":"// before (test packet builder)\nlet len: VarUInt = VarUInt(5000);\n// after\nlet len: VarUInt = VarUInt(64); // must be <= 1024","handlingStrategy":"validation","validationCode":"fn valid_collection_len(len: u32) -> bool { len <= 1024 }","typeGuard":"fn fits_collection(len: u32) -> Option<usize> { (len <= 1024).then(|| len as usize) }","tryCatchPattern":"match decode_item_stack_request(buf) {\n    Err(e) if e.kind() == ErrorKind::InvalidData => drop_packet(peer, e),\n    Err(e) => return Err(e),\n    Ok(req) => handle(req),\n}","preventionTips":["Keep client and server Bedrock protocol versions in sync","Cap collection sizes in any packet-generating test fixtures","Monitor logs for repeated oversized-length packets (likely hostile peers)","Never trust client-supplied length prefixes; validate before allocating"],"tags":["protocol","bedrock","deserialization","packet-limit"],"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"}