{"record":{"id":"25b355add03be1c0","repo":"Pumpkin-MC/Pumpkin","slug":"item-stack-response-count-exceeds-4096","errorCode":null,"errorMessage":"item stack response count exceeds 4096","messagePattern":"item stack response count exceeds 4096","errorType":"validation","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/bedrock/client/item_stack_response.rs","lineNumber":82,"sourceCode":"            VarUInt(self.containers.len() as u32).write(writer)?;\n            for info in &self.containers {\n                info.write(writer)?;\n            }\n        }\n        Ok(())\n    }\n}\n\n#[derive(Debug, Clone)]\n#[packet(148)]\npub struct CItemStackResponse {\n    pub responses: Vec<ItemStackResponseInfo>,\n}\n\nimpl PacketWrite for CItemStackResponse {\n    fn write<W: Write>(&self, writer: &mut W) -> Result<(), Error> {\n        if self.responses.len() > 4096 {\n            return Err(Error::new(\n                std::io::ErrorKind::InvalidInput,\n                \"item stack response count exceeds 4096\",\n            ));\n        }\n        VarUInt(self.responses.len() as u32).write(writer)?;\n        for response in &self.responses {\n            response.write(writer)?;\n        }\n        Ok(())\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn rejects_out_of_range_durability_correction() {","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/bedrock/client/item_stack_response.rs#L64-L100","documentation":"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.","triggerScenarios":"Building a CItemStackResponse whose responses vec exceeds 4096 ItemStackResponseInfo entries and calling write.","commonSituations":"Bulk inventory operations (large chest dumps, mass-crafting, world-edit style item changes) accumulating thousands of slot responses in one packet.","solutions":["Chunk the responses into batches of at most 4096 and send multiple CItemStackResponse packets.","Deduplicate/merge slot responses before packing (same slot requested multiple times).","Cap the inventory-diff collector at 4096 entries and spill the remainder to the next tick."],"exampleFix":"// before\nCItemStackResponse { responses: all_responses }.write(&mut writer)?;\n// after\nfor batch in all_responses.chunks(4096) {\n    CItemStackResponse { responses: batch.to_vec() }.write(&mut writer)?;\n}","handlingStrategy":"validation","validationCode":"if responses.len() > 4096 {\n    // split before serializing\n    for batch in responses.chunks(4096) { send(CItemStackResponse { responses: batch.to_vec() }); }\n    return Ok(());\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = packet.write(&mut writer) {\n    log::error!(\"failed to write item stack response: {e}\");\n    return Err(e);\n}","preventionTips":["Chunk large response sets at collection time, not at write time.","Merge duplicate slot responses before packing.","Enforce a hard cap of 4096 responses in inventory-diff collectors."],"tags":["protocol","bedrock","packet-size","serialization"],"backgroundTag":"payload-too-large","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"}