[GH-ISSUE #5223] Native mods: changing an item entity from the pickup hook crashes the server thread #1602

Closed
opened 2026-11-02 15:48:18 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @arismoko on GitHub (Oct 31, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5223

Originally assigned to: @arismoko on GitHub.

🤖 Filed by Aria's agent swarm, Dyna, not by Aria.

#5151 merged with the crash from its review still in place (0d2a9d840).

What happens: guest_pickups (crates/horizon-client/src/game/lan_actions.rs, around line 3586) collects indices into self.dropped and then calls native_pickup_refused, which runs a mod's native_item_picked_up hook. Since #5151, that hook may call native_set_item_entity, which removes the entity from self.dropped when the new stack is empty (native_hooks.rs, around line 1432). After the hook returns, guest_pickups keeps using its old index i:

  • If the removed item was the last one, self.dropped[i] panics on the server thread.
  • Otherwise i now points at a different item, which the player picks up or which gets pickup_delay = 10 instead.

To reproduce: a native mod whose native_item_picked_up calls native_set_item_entity on the touched item with an empty stack, and refuses or allows the pickup. Drop one item, then walk over it: the server thread panics on an index out of bounds.

Fix direction: look the item up again by its id after the hook (self.dropped.iter().position(|e| e.id == item_id)) and skip it if it is gone, instead of trusting i.

Part of #4953.

The recommended end-to-end test mod, horizon-machine-sample, was not used to find this; the crash was found by reading the code during review. A fix PR will include an in-game check.

Originally created by @arismoko on GitHub (Oct 31, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5223 Originally assigned to: @arismoko on GitHub. > 🤖 Filed by Aria's agent swarm, Dyna, not by Aria. #5151 merged with the crash from its review still in place (`0d2a9d840`). **What happens:** `guest_pickups` (`crates/horizon-client/src/game/lan_actions.rs`, around line 3586) collects indices into `self.dropped` and then calls `native_pickup_refused`, which runs a mod's `native_item_picked_up` hook. Since #5151, that hook may call `native_set_item_entity`, which removes the entity from `self.dropped` when the new stack is empty (`native_hooks.rs`, around line 1432). After the hook returns, `guest_pickups` keeps using its old index `i`: - If the removed item was the last one, `self.dropped[i]` panics on the server thread. - Otherwise `i` now points at a different item, which the player picks up or which gets `pickup_delay = 10` instead. **To reproduce:** a native mod whose `native_item_picked_up` calls `native_set_item_entity` on the touched item with an empty stack, and refuses or allows the pickup. Drop one item, then walk over it: the server thread panics on an index out of bounds. **Fix direction:** look the item up again by its id after the hook (`self.dropped.iter().position(|e| e.id == item_id)`) and skip it if it is gone, instead of trusting `i`. Part of #4953. The recommended end-to-end test mod, [horizon-machine-sample](https://github.com/arismoko/horizon-machine-sample), was not used to find this; the crash was found by reading the code during review. A fix PR will include an in-game check.
Author
Owner

@arismoko commented on GitHub (Oct 31, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6545599528 --> @arismoko commented on GitHub (Oct 31, 2026): 🤖 Agent: /claim
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#1602
No description provided.