Skip to content

fix: malformed packet crash #889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

TestingPlant
Copy link
Collaborator

When a client sends a malformed packet, the server will crash because it used entity.destruct to disconnect players for malformed packets which leads to an abort because, when the server receives PlayerDisconnect from the proxy, the server will try to set PendingRemove on the already-destructed entity.

This PR fixes these errors on player disconnects.

This prevents possible bugs from forgetting to remove the player from
the player reigstry when calling shutdown. It also removes the player
from the positions map.
Using entity.destruct to disconnect players leads to an abort because,
when the server receives PlayerDisconnect from the proxy, the server
will try to set PendingRemove on the already-destructed entity,
causing an abort.

Sending DisconnectS2c was removed because it is not possible to send
packets to disconnected players.
The channel is closed which makes the recv loop end. Therefore, sending
a shutdown message is not needed.
@github-actions github-actions bot added the fix label Apr 27, 2025
Copy link

Benchmark Results for general

ray_intersection/aabb_size_0.1                     [  33.9 ns ...  33.8 ns ]      -0.28%
ray_intersection/aabb_size_1                       [  33.8 ns ...  33.6 ns ]      -0.52%
ray_intersection/aabb_size_10                      [  24.4 ns ...  24.4 ns ]      +0.30%
ray_intersection/ray_distance_1                    [  13.8 ns ...  13.8 ns ]      -0.09%
ray_intersection/ray_distance_5                    [  13.8 ns ...  13.8 ns ]      -0.05%
ray_intersection/ray_distance_20                   [  13.8 ns ...  13.8 ns ]      -0.13%
overlap/no_overlap                                 [  24.7 ns ...  24.8 ns ]      +0.27%
overlap/partial_overlap                            [  25.0 ns ...  25.4 ns ]      +1.47%
overlap/full_containment                           [  22.5 ns ...  22.5 ns ]      +0.15%
point_containment/inside                           [   5.5 ns ...   5.0 ns ]     -10.08%
point_containment/outside                          [   4.4 ns ...   4.4 ns ]      +0.13%
point_containment/boundary                         [   4.9 ns ...   4.9 ns ]      +0.19%

Comparing to 4c402d0

Copy link

codecov bot commented Apr 27, 2025

Codecov Report

Attention: Patch coverage is 4.25532% with 45 lines in your changes missing coverage. Please review.

Project coverage is 20.85%. Comparing base (4c402d0) to head (970c342).

Files with missing lines Patch % Lines
crates/hyperion/src/net/mod.rs 0.00% 19 Missing ⚠️
crates/hyperion/src/ingress/mod.rs 22.22% 7 Missing ⚠️
crates/hyperion-proxy/src/egress.rs 0.00% 5 Missing ⚠️
crates/hyperion-proxy/src/player.rs 0.00% 5 Missing ⚠️
crates/hyperion-proxy/src/cache.rs 0.00% 3 Missing ⚠️
crates/hyperion-proxy/src/data.rs 0.00% 3 Missing ⚠️
crates/hyperion/src/egress/player_join/mod.rs 0.00% 2 Missing ⚠️
crates/hyperion-proto/src/server_to_proxy.rs 0.00% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main     #889      +/-   ##
==========================================
- Coverage   20.85%   20.85%   -0.01%     
==========================================
  Files         161      161              
  Lines       16867    16864       -3     
  Branches      468      463       -5     
==========================================
- Hits         3518     3517       -1     
+ Misses      13285    13283       -2     
  Partials       64       64              
Files with missing lines Coverage Δ
crates/hyperion-proto/src/server_to_proxy.rs 12.50% <0.00%> (-1.79%) ⬇️
crates/hyperion/src/egress/player_join/mod.rs 29.05% <0.00%> (-0.13%) ⬇️
crates/hyperion-proxy/src/cache.rs 0.00% <0.00%> (ø)
crates/hyperion-proxy/src/data.rs 0.00% <0.00%> (ø)
crates/hyperion-proxy/src/egress.rs 0.00% <0.00%> (ø)
crates/hyperion-proxy/src/player.rs 0.00% <0.00%> (ø)
crates/hyperion/src/ingress/mod.rs 22.83% <22.22%> (+0.51%) ⬆️
crates/hyperion/src/net/mod.rs 6.60% <0.00%> (-0.31%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@andrewgazelka andrewgazelka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally looks good. However, requires a couple of changes.

#[derive(Component, Debug)]
pub struct PendingRemove {
pub reason: String,
_private: u8,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the point of this _private field? why can't this just be a ZST

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flecs doesn't allow zero sized components. The _private field also prevents other modules from constructing PendingRemove since it should only be sent by the PlayerDisconnect proxy message.

Copy link
Member

@andrewgazelka andrewgazelka Apr 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flecs doesn't allow zero sized components. The _private field also prevents other modules from constructing PendingRemove since it should only be sent by the PlayerDisconnect proxy message.

when you use .with I believe flecs does. I have definitely used ZSTs before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I change it to

#[derive(Component, Debug)]
pub struct PendingRemove;

I get the following error:

error[E0277]: the size of type `PendingRemove` should not be zero, should not be a tag.
   --> crates/hyperion/src/ingress/mod.rs:336:47
    |
336 |                 world.entity_from_id(*id).set(PendingRemove);
    |                                           --- ^^^^^^^^^^^^^ Supports only non-empty components
    |                                           |
    |                                           required by a bound introduced by this call
    |
    = help: the trait `flecs_ecs::core::DataComponent` is not implemented for `PendingRemove`
    = help: the following other types implement trait `flecs_ecs::core::DataComponent`:
              &T
              &mut T
              (T, U)
              ActiveAnimation
              AdditionalHearts
              AirSupply
              AppId
              ArrowsInEntity
            and 137 others
note: required by a bound in `flecs_ecs::core::entity_view::entity_view_mut::<impl flecs_ecs::core::EntityView<'a>>::set`
   --> /home/remote-dev/.cargo/git/checkouts/flecs-rust-182003fcd2303c9b/f2762ad/flecs_ecs/src/core/entity_view/entity_view_mut.rs:860:33
    |
860 |     pub fn set<T: ComponentId + DataComponent>(self, component: T) -> Self {
    |                                 ^^^^^^^^^^^^^ required by this bound in `flecs_ecs::core::entity_view::entity_view_mut::<impl EntityView<'a>>::set`

Copy link

Benchmark Results for general

ray_intersection/aabb_size_0.1                     [  33.5 ns ...  33.4 ns ]      -0.27%
ray_intersection/aabb_size_1                       [  33.9 ns ...  33.8 ns ]      -0.24%
ray_intersection/aabb_size_10                      [  24.3 ns ...  24.3 ns ]      -0.18%
ray_intersection/ray_distance_1                    [  13.8 ns ...  13.8 ns ]      +0.09%
ray_intersection/ray_distance_5                    [  13.8 ns ...  13.8 ns ]      -0.19%
ray_intersection/ray_distance_20                   [  13.8 ns ...  13.8 ns ]      -0.03%
overlap/no_overlap                                 [  24.9 ns ...  24.8 ns ]      -0.36%
overlap/partial_overlap                            [  25.0 ns ...  25.1 ns ]      +0.35%
overlap/full_containment                           [  22.5 ns ...  22.5 ns ]      -0.10%
point_containment/inside                           [   4.9 ns ...   4.9 ns ]      -0.13%
point_containment/outside                          [   4.4 ns ...   4.4 ns ]      -0.30%
point_containment/boundary                         [   5.0 ns ...   4.9 ns ]      -0.21%

Comparing to 4c402d0

Copy link

Benchmark Results for general

ray_intersection/aabb_size_0.1                     [  33.9 ns ...  33.8 ns ]      -0.09%
ray_intersection/aabb_size_1                       [  33.7 ns ...  33.8 ns ]      +0.17%
ray_intersection/aabb_size_10                      [  24.0 ns ...  24.0 ns ]      +0.02%
ray_intersection/ray_distance_1                    [  13.8 ns ...  13.8 ns ]      +0.19%
ray_intersection/ray_distance_5                    [  13.8 ns ...  13.8 ns ]      -0.21%
ray_intersection/ray_distance_20                   [  13.8 ns ...  13.8 ns ]      +0.04%
overlap/no_overlap                                 [  24.8 ns ...  24.8 ns ]      -0.04%
overlap/partial_overlap                            [  25.0 ns ...  25.2 ns ]      +0.57%
overlap/full_containment                           [  22.5 ns ...  22.5 ns ]      -0.09%
point_containment/inside                           [   4.9 ns ...   4.9 ns ]      +0.10%
point_containment/outside                          [   4.4 ns ...   4.4 ns ]      +0.04%
point_containment/boundary                         [   5.0 ns ...   5.0 ns ]      -0.05%

Comparing to 4c402d0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants