Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Don't allow plugins to set problematic velocity vectors #412

Closed
wants to merge 3 commits into from
Closed

Don't allow plugins to set problematic velocity vectors #412

wants to merge 3 commits into from

Conversation

Packsolite
Copy link

@Packsolite Packsolite commented May 14, 2022

Description

Currently plugins can use the api to set a players velocity to illegal values like NaN which causes the server to freeze under some circumstances.

In Entity.java:541 we can find this loop:

                for (d9 = 0.05D; d0 != 0.0D && this.world.getCubes(this, this.getBoundingBox().c(d0, -1.0D, 0.0D)).isEmpty(); d6 = d0) {
                    if (d0 < d9 && d0 >= -d9) {
                        d0 = 0.0D;
                    } else if (d0 > 0.0D) {
                        d0 -= d9;
                    } else {
                        d0 += d9;
                    }
                }

The check d0 != 0.0D is important here: d0 will be initialized with the entities motionX.
If motionX (or in the following loops motionY, motionZ) is NaN , this check is always false since NaN += x = NaN resulting in an endless loop and the server to freeze/crash.

The fix implemented in this PR is to disallow plugins to set any NaN values through the setVelocity(...) api.
Another way of fixing this would be to check if d0 is NaN and overriding it with 0. But i think it's better to not allow setting NaN in the first place at the api layer.
Fixes #409

How has this been tested?

On a production server with 20-30 players for 24 hours without any crashes.

Checklist:

  • I have reviewed my code thoroughly.
  • I have tested my code.
  • My changes generate no new warnings

@Packsolite Packsolite closed this by deleting the head repository Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Applying certain velocities while sneaking freezes Nacho
1 participant