Pumpkin-MC/Pumpkin · error

length exceeds

Error message

{name} length {len} exceeds {MAX_COLLECTION_LENGTH}

What it means

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.

Solutions

  1. Update the Bedrock client/server to matching protocol versions
  2. Inspect the packet capture to see which collection declares the oversized length
  3. If writing a test, cap generated collection lengths at 1024
  4. If intentionally sending large payloads, raise MAX_COLLECTION_LENGTH in crates/pumpkin-protocol/src/bedrock/server/item_stack_request.rs

Example fix

// before (test packet builder)
let len: VarUInt = VarUInt(5000);
// after
let len: VarUInt = VarUInt(64); // must be <= 1024
Defensive patterns

Strategy: validation

Validate before calling

fn valid_collection_len(len: u32) -> bool { len <= 1024 }

Type guard

fn fits_collection(len: u32) -> Option<usize> { (len <= 1024).then(|| len as usize) }

Try / catch

match decode_item_stack_request(buf) {
    Err(e) if e.kind() == ErrorKind::InvalidData => drop_packet(peer, e),
    Err(e) => return Err(e),
    Ok(req) => handle(req),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09). Data as JSON: /api/errors/861186be9182151d. Report an issue: GitHub.

Appendix: source

Thrown at crates/pumpkin-protocol/src/bedrock/server/item_stack_request.rs:15

use std::io::{Error, ErrorKind, Read};

use crate::{
    bedrock::network_item::FullContainerName,
    codec::{var_int::VarInt, var_uint::VarUInt},
    serial::{PacketRead, PacketWrite},
};
use pumpkin_macros::packet;

const MAX_COLLECTION_LENGTH: u32 = 1024;

fn collection_length<R: Read>(reader: &mut R, name: &str) -> Result<usize, Error> {
    let len = VarUInt::read(reader)?.0;
    if len > MAX_COLLECTION_LENGTH {
        return Err(Error::new(
            ErrorKind::InvalidData,
            format!("{name} length {len} exceeds {MAX_COLLECTION_LENGTH}"),
        ));
    }
    Ok(len as usize)
}

#[derive(Debug, PacketRead, PacketWrite)]
pub struct ItemStackRequestSlotInfo {
    pub container_name: FullContainerName,
    pub slot_id: u8,
    pub stack_id: i32,
}

#[derive(Debug)]
pub struct StackRequestItem {
    pub identifier: Option<String>,
    pub metadata_value: VarInt,

View on GitHub (pinned to 8d4639e25a)