aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0841-Guard-against-invalid-entity-positions.patch
blob: 3b1a878337cb9b3dda3e4a7afb43cbe89b20248c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Thu, 31 Mar 2022 05:18:28 -0700
Subject: [PATCH] Guard against invalid entity positions

Anything not finite should be blocked and logged

diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 8d80717589046271119552726e3b4bbd403dac65..7f104aa35dce81d2299cb7b4a3e560e67105da4a 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -4199,11 +4199,33 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
         return this.getZ((2.0D * this.random.nextDouble() - 1.0D) * widthScale);
     }
 
+    // Paper start - block invalid positions
+    public static boolean checkPosition(Entity entity, double newX, double newY, double newZ) {
+        if (Double.isFinite(newX) && Double.isFinite(newY) && Double.isFinite(newZ)) {
+            return true;
+        }
+
+        String entityInfo = null;
+        try {
+            entityInfo = entity.toString();
+        } catch (Exception ex) {
+            entityInfo = "[Entity info unavailable] ";
+        }
+        LOGGER.error("New entity position is invalid! Tried to set invalid position (" + newX + "," + newY + "," + newZ + ") for entity " + entity.getClass().getName() + " located at " + entity.position + ", entity info: " + entityInfo, new Throwable());
+        return false;
+    }
+    // Paper end - block invalid positions
+
     public final void setPosRaw(double x, double y, double z) {
         // Paper start
         this.setPosRaw(x, y, z, false);
     }
     public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) {
+        // Paper start - block invalid positions
+        if (!checkPosition(this, x, y, z)) {
+            return;
+        }
+        // Paper end - block invalid positions
         // Paper end
         // Paper start - rewrite chunk system
         if (this.updatingSectionStatus) {