Pumpkin-MC/Pumpkin · error · std::io::Error

item stack response count exceeds 4096

Error message

item stack response count exceeds 4096

What it means

Raised by CItemStackResponse::write when the responses vector holds more than 4096 entries. The Bedrock packet protocol bounds the response count (encoded as VarUInt but validated against a 4096 cap) to prevent oversized/malicious packets, so the write refuses to serialize.

Solutions

  1. Chunk the responses into batches of at most 4096 and send multiple CItemStackResponse packets.
  2. Deduplicate/merge slot responses before packing (same slot requested multiple times).
  3. Cap the inventory-diff collector at 4096 entries and spill the remainder to the next tick.

Example fix

// before
CItemStackResponse { responses: all_responses }.write(&mut writer)?;
// after
for batch in all_responses.chunks(4096) {
    CItemStackResponse { responses: batch.to_vec() }.write(&mut writer)?;
}
Defensive patterns

Strategy: validation

Validate before calling

if responses.len() > 4096 {
    // split before serializing
    for batch in responses.chunks(4096) { send(CItemStackResponse { responses: batch.to_vec() }); }
    return Ok(());
}

Try / catch

if let Err(e) = packet.write(&mut writer) {
    log::error!("failed to write item stack response: {e}");
    return Err(e);
}

Prevention

When it happens

Trigger: Building a CItemStackResponse whose responses vec exceeds 4096 ItemStackResponseInfo entries and calling write.

Common situations: Bulk inventory operations (large chest dumps, mass-crafting, world-edit style item changes) accumulating thousands of slot responses in one packet.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at crates/pumpkin-protocol/src/bedrock/client/item_stack_response.rs:82

            VarUInt(self.containers.len() as u32).write(writer)?;
            for info in &self.containers {
                info.write(writer)?;
            }
        }
        Ok(())
    }
}

#[derive(Debug, Clone)]
#[packet(148)]
pub struct CItemStackResponse {
    pub responses: Vec<ItemStackResponseInfo>,
}

impl PacketWrite for CItemStackResponse {
    fn write<W: Write>(&self, writer: &mut W) -> Result<(), Error> {
        if self.responses.len() > 4096 {
            return Err(Error::new(
                std::io::ErrorKind::InvalidInput,
                "item stack response count exceeds 4096",
            ));
        }
        VarUInt(self.responses.len() as u32).write(writer)?;
        for response in &self.responses {
            response.write(writer)?;
        }
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn rejects_out_of_range_durability_correction() {

View on GitHub (pinned to 8d4639e25a)