{"record":{"id":"18adb54f1466c462","repo":"Pumpkin-MC/Pumpkin","slug":"invalid-slot","errorCode":null,"errorMessage":"Invalid slot","messagePattern":"Invalid slot","errorType":"exception","errorClass":"InventoryError","httpStatus":null,"severity":"warning","filePath":"crates/pumpkin-inventory/src/error.rs","lineNumber":13,"sourceCode":"use thiserror::Error;\n\n/// Errors that can occur during inventory operations.\n///\n/// These errors represent various failure conditions when handling inventory\n/// interactions, such as invalid slot indices, permission issues, or protocol errors.\n#[derive(Error, Debug)]\npub enum InventoryError {\n    /// Failed to acquire a lock on an inventory or slot.\n    #[error(\"Unable to lock\")]\n    LockError,\n    /// The specified slot index is invalid or out of bounds.\n    #[error(\"Invalid slot\")]\n    InvalidSlot,\n    /// A player attempted to interact with a container that is closed.\n    ///\n    /// The parameter is the player's entity ID.\n    #[error(\"Player '{0}' tried to interact with a closed container\")]\n    ClosedContainerInteract(i32),\n    /// Multiple players attempted to drag items in the same container simultaneously.\n    #[error(\"Multiple players dragging in a container at once\")]\n    MultiplePlayersDragging,\n    /// Drag operation was performed out of order (e.g., end before start).\n    #[error(\"Out of order dragging\")]\n    OutOfOrderDragging,\n    /// The received inventory packet is malformed or invalid.\n    #[error(\"Invalid inventory packet\")]\n    InvalidPacket,\n    /// The player lacks permission to perform this inventory operation.\n    #[error(\"Player does not have enough permissions\")]\n    PermissionError,","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-inventory/src/error.rs#L1-L31","documentation":"InventoryError::InvalidSlot indicates the specified slot index is invalid or out of bounds for the target inventory. The library uses it to safely reject slot references that do not exist rather than panicking on an array index.","triggerScenarios":"Calling inventory get/set/interaction APIs with a slot index negative or >= the inventory size — e.g. malformed click packets with crafted slot numbers, or using a container-window slot index directly as an inventory-array index without converting through the slot mapping.","commonSituations":"Protocol clients sending out-of-range slot numbers in click/drag packets; hotbar vs container slot index confusion; inventory resized while a client still references old slot numbers.","solutions":["Validate the slot index against the inventory size before calling slot APIs","Convert protocol (window) slot numbers to internal inventory indices via the container's slot mapping before use","Silently ignore or log-and-discard invalid slot packets from clients instead of propagating the error","Check for off-by-one errors after inventory size changes"],"exampleFix":"// before\nlet item = inventory.slot(packet.slot)?;\n// after\nif packet.slot < 0 || packet.slot as usize >= inventory.size() {\n    log::warn!(\"client sent invalid slot {}\", packet.slot);\n    return Ok(());\n}\nlet item = inventory.slot(packet.slot as usize)?;","handlingStrategy":"validation","validationCode":"fn slot_is_valid(slot: i32, size: usize) -> bool {\n    slot >= 0 && (slot as usize) < size\n}","typeGuard":"fn valid_slot(slot: i32, inv: &dyn Inventory) -> Option<usize> {\n    if slot >= 0 && (slot as usize) < inv.size() { Some(slot as usize) } else { None }\n}","tryCatchPattern":"match container.handle_click(player_id, click) {\n    Err(InventoryError::InvalidSlot) => {\n        log::warn!(\"invalid slot in packet from {player_id}; ignoring\");\n    }\n    r => r?,\n}","preventionTips":["Always bounds-check slot numbers from network packets against inventory size","Convert window slot indices to internal indices via the container's slot mapping","Re-check slot validity after any inventory resize or session change","Ignore (don't propagate) invalid-slot packets coming from clients"],"tags":["inventory","validation","bounds","protocol","rust"],"backgroundTag":"index-out-of-bounds","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"}