From e1a3e2dc0013796fbfff66a586f65a55d9013b40 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sat, 11 Feb 2023 23:04:52 -0500 Subject: [PATCH] make dropping an item in creative not crash the server (#234) ## Description Added a quick and dirty bounds check because we haven't created drop item/itemstack event(s) yet. ## Test Plan use the `building` example Steps: 1. `cargo run --example building` 2. open inventory 3. pick an item 4. drop the item outside of the inventory window 5. see that the server does not panic #### Related fixes #233 --- crates/valence/src/inventory.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/valence/src/inventory.rs b/crates/valence/src/inventory.rs index 43246b4..2833349 100644 --- a/crates/valence/src/inventory.rs +++ b/crates/valence/src/inventory.rs @@ -542,6 +542,10 @@ pub(crate) fn handle_set_slot_creative( // the client is not in creative mode, ignore continue; } + if event.slot < 0 || event.slot >= inventory.slot_count() as i16 { + // the client is trying to interact with a slot that does not exist, ignore + continue; + } inventory.replace_slot(event.slot as u16, event.clicked_item.clone()); inventory.modified &= !(1 << event.slot); // clear the modified bit, since we are about to send the update client.inventory_state_id += 1;