{"record":{"id":"7988f9b9e56582b9","repo":"Pumpkin-MC/Pumpkin","slug":"vector-length-len-exceeds-limit-of-65536","errorCode":null,"errorMessage":"Vector length {len} exceeds limit of 65536","messagePattern":"Vector length (.+?) exceeds limit of 65536","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/pumpkin-protocol/src/serial/deserializer.rs","lineNumber":177,"sourceCode":"            return Err(Error::new(\n                ErrorKind::InvalidData,\n                format!(\"String length {len} exceeds maximum of {MAX_STRING_LENGTH}\"),\n            ));\n        }\n\n        let mut buf = vec![0u8; len];\n        reader.read_exact(&mut buf)?;\n\n        Self::from_utf8(buf)\n            .map_err(|_| Error::new(ErrorKind::InvalidData, \"Invalid UTF-8 sequence\"))\n    }\n}\n\nimpl<T: PacketRead> PacketRead for Vec<T> {\n    fn read<R: Read>(reader: &mut R) -> Result<Self, Error> {\n        let len = VarUInt::read(reader)?.0 as usize;\n        if len > 65536 {\n            return Err(Error::new(\n                ErrorKind::InvalidData,\n                format!(\"Vector length {len} exceeds limit of 65536\"),\n            ));\n        }\n        let mut buf = Self::with_capacity(len.min(1024));\n        for _ in 0..len {\n            buf.push(T::read(reader)?);\n        }\n        Ok(buf)\n    }\n}\n\nimpl<T: PacketRead> PacketRead for Vector3<T> {\n    fn read<R: Read>(reader: &mut R) -> Result<Self, Error> {\n        Ok(Self {\n            x: T::read(reader)?,\n            y: T::read(reader)?,\n            z: T::read(reader)?,","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/serial/deserializer.rs#L159-L195","documentation":"Thrown by the `PacketRead for Vec<T>` impl when the length prefix read as VarUInt exceeds 65536 elements. The cap prevents malicious packets from triggering enormous allocations. Note capacity is only preallocated for min(len,1024), so oversized lengths are rejected before any growth.","triggerScenarios":"Deserializing a Vec<T> field whose VarUInt length prefix is > 65536; corrupted or malicious packet data; stream desync misreading bytes as a length.","commonSituations":"Malicious client sending huge array counts; desynced byte stream where a random int is parsed as the vector length; protocol version mismatch.","solutions":["Verify protocol version alignment between client and server","Check for desync: confirm preceding fields parsed correctly","Reject/drop the packet and optionally ban the offending peer","If the data is legitimately large, raise the 65536 limit consciously in a fork"],"exampleFix":"// before\nlet items: Vec<ItemStack> = reader.read()?;\n// after\nmatch Vec::<ItemStack>::read(&mut reader) {\n    Ok(items) => items,\n    Err(e) => { log::warn!(\"oversized vec in packet: {e}\"); drop_connection(); }\n}","handlingStrategy":"validation","validationCode":"let (count, _) = VarUInt::peek(reader)?;\nif count > 65536 { return Err(PacketError::OversizedVector(count)); }","typeGuard":"fn is_valid_vec_len(len: usize) -> bool { len <= 65536 }","tryCatchPattern":"match Vec::<T>::read(&mut reader) {\n    Ok(v) => v,\n    Err(e) => { log::warn!(\"vec limit exceeded: {e}\"); drop_connection(); }\n}","preventionTips":["Cap element counts at the protocol-design layer","Rate-limit or ban peers sending oversized length prefixes","Test deserializers with fuzzed/malicious inputs"],"tags":["protocol","serialization","dos-protection"],"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-17T15:17:12.973Z"}