Skip to content

Commit cb198ff

Browse files
committed
Fix chunk range int overflow
1 parent 6f0762c commit cb198ff

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Nassim Jahnke <jahnke.nassim@gmail.com>
3+
Date: Tue, 11 Jan 2022 19:31:46 +0100
4+
Subject: [PATCH] Fix int overflow in chunk range check
5+
6+
7+
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
8+
index 16fd37a5048ee4b2fa6760c66af6f14e8fd71f89..0a04980a8015fe08907a040f0f3ff537267bd462 100644
9+
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
10+
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
11+
@@ -621,9 +621,11 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
12+
public static boolean isChunkInRange(int x1, int z1, int x2, int z2, int distance) {
13+
int j1 = Math.max(0, Math.abs(x1 - x2) - 1);
14+
int k1 = Math.max(0, Math.abs(z1 - z2) - 1);
15+
- int l1 = Math.max(0, Math.max(j1, k1) - 1);
16+
- int i2 = Math.min(j1, k1);
17+
- int j2 = i2 * i2 + l1 * l1;
18+
+ // Paper start - fix integer overflow
19+
+ long l1 = Math.max(0, Math.max(j1, k1) - 1);
20+
+ long i2 = Math.min(j1, k1);
21+
+ long j2 = i2 * i2 + l1 * l1;
22+
+ // Paper end
23+
int k2 = distance - 1;
24+
int l2 = k2 * k2;
25+

0 commit comments

Comments
 (0)