Fix IndexOutOfBoundsException when sending too many changes

Authored-by: Ivan Pekov <ivan@mrivanplays.com>
This commit is contained in:
budgidiere 2020-09-29 12:47:32 -05:00 committed by GitHub
parent 42a9cb768c
commit 5b1f445951
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 129 additions and 3 deletions

View File

@ -53,6 +53,7 @@ # Patches
| server | Fix &quot;Unable to save chunk&quot; error | Ivan Pekov | | | server | Fix &quot;Unable to save chunk&quot; error | Ivan Pekov | |
| server | Fix &#39;outdated server&#39; showing in ping before server fully | William Blake Galbreath | | | server | Fix &#39;outdated server&#39; showing in ping before server fully | William Blake Galbreath | |
| server | Fix Bukkit.createInventory() with type LECTERN | willies952002 | | | server | Fix Bukkit.createInventory() with type LECTERN | willies952002 | |
| server | Fix IndexOutOfBoundsException when sending too many changes | Ivan Pekov | |
| server | Fix LightEngineThreaded memory leak | Ivan Pekov | | | server | Fix LightEngineThreaded memory leak | Ivan Pekov | |
| server | Fix exp drop of zombie pigmen (MC-56653) | Phoenix616 | | | server | Fix exp drop of zombie pigmen (MC-56653) | Phoenix616 | |
| server | Fix lead fall dmg config | tr7zw | | | server | Fix lead fall dmg config | tr7zw | |
@ -117,6 +118,7 @@ # Patches
| server | Stop squids floating on top of water | William Blake Galbreath | | | server | Stop squids floating on top of water | William Blake Galbreath | |
| server | Stop wasting resources on JsonList#get | Ivan Pekov | | | server | Stop wasting resources on JsonList#get | Ivan Pekov | |
| server | Swaps the predicate order of collision | ㄗㄠˋ ㄑㄧˊ | | | server | Swaps the predicate order of collision | ㄗㄠˋ ㄑㄧˊ | |
| server | Tic-Tacs Threading Fix | gegy1000 | |
| server | Timings stuff | William Blake Galbreath | | | server | Timings stuff | William Blake Galbreath | |
| server | Tulips change fox type | William Blake Galbreath | | | server | Tulips change fox type | William Blake Galbreath | |
| server | Use block distance in portal search radius | Patrick Hemmer | | | server | Use block distance in portal search radius | Patrick Hemmer | |

View File

@ -3134,7 +3134,7 @@ index 44b67715e6c1b113b4651a965e8006e9a10a05bf..00000000000000000000000000000000
- // Purpur end - // Purpur end
- } - }
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
index 16fd48c617ebced744966fd1b4cd155c20774ef4..b3651d69720cd40593d0febb58380203972ca87b 100644 index 210cb10ea75b99d3b5d7b5bce5cea44e3cc0fc20..62012d2b780d3399bd641ca3ca4a4ac127e3bcb5 100644
--- a/src/main/java/org/bukkit/craftbukkit/Main.java --- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/src/main/java/org/bukkit/craftbukkit/Main.java
@@ -154,6 +154,14 @@ public class Main { @@ -154,6 +154,14 @@ public class Main {

View File

@ -304,7 +304,7 @@ index 4bae0e82bc25b576a23b5f05af7c3ad944a54bcf..78d7fc805a1aeb0d31e51a5aa68e92d9
public void restart() { public void restart() {
org.spigotmc.RestartCommand.restart(); org.spigotmc.RestartCommand.restart();
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
index b3651d69720cd40593d0febb58380203972ca87b..e1fdb891ca612cd360983ce121b01faab3f50d68 100644 index 62012d2b780d3399bd641ca3ca4a4ac127e3bcb5..dddba89eee0181c066ad979bc2b75e8de36e7458 100644
--- a/src/main/java/org/bukkit/craftbukkit/Main.java --- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/src/main/java/org/bukkit/craftbukkit/Main.java
@@ -162,6 +162,14 @@ public class Main { @@ -162,6 +162,14 @@ public class Main {

View File

@ -58,7 +58,7 @@ index 72d7a017f2aa7f2fde3b5de437e7fd2e051edd24..6c280d64bb069fba0d52a7d8b4eb6a08
this.setPVP(dedicatedserverproperties.pvp); this.setPVP(dedicatedserverproperties.pvp);
this.setAllowFlight(dedicatedserverproperties.allowFlight); this.setAllowFlight(dedicatedserverproperties.allowFlight);
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
index e1fdb891ca612cd360983ce121b01faab3f50d68..ced65104baf3a8a7d4a1aaaba0a863eaf0a5c169 100644 index dddba89eee0181c066ad979bc2b75e8de36e7458..2b7bfeb79200458912aef6b20ee53c4c276b3451 100644
--- a/src/main/java/org/bukkit/craftbukkit/Main.java --- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/src/main/java/org/bukkit/craftbukkit/Main.java
@@ -303,7 +303,7 @@ public class Main { @@ -303,7 +303,7 @@ public class Main {

View File

@ -0,0 +1,124 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Tue, 29 Sep 2020 19:25:49 +0300
Subject: [PATCH] Fix IndexOutOfBoundsException when sending too many changes
diff --git a/src/main/java/net/minecraft/server/PacketDataSerializer.java b/src/main/java/net/minecraft/server/PacketDataSerializer.java
index f43193c1090238f2241b878120247d1b3d0d4e57..a7783944e8e4ee2a164aa19b3cc342252bc84ee2 100644
--- a/src/main/java/net/minecraft/server/PacketDataSerializer.java
+++ b/src/main/java/net/minecraft/server/PacketDataSerializer.java
@@ -182,6 +182,7 @@ public class PacketDataSerializer extends ByteBuf {
return i;
}
+ public final long readVarLong() { return j(); } // Yatopia - OBFHELPER
public long j() {
long i = 0L;
int j = 0;
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutMultiBlockChange.java b/src/main/java/net/minecraft/server/PacketPlayOutMultiBlockChange.java
index f260459d70053ffd17952aebf3e0410666f9bcd0..cae074a9a29fe5ddab74ec983a07c05d1439283d 100644
--- a/src/main/java/net/minecraft/server/PacketPlayOutMultiBlockChange.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutMultiBlockChange.java
@@ -8,8 +8,8 @@ import java.util.function.BiConsumer;
public class PacketPlayOutMultiBlockChange implements Packet<PacketListenerPlayOut> {
private SectionPosition a;
- private short[] b;
- private IBlockData[] c;
+ private java.util.List<Short> b; // Yatopia - change to list
+ private java.util.List<IBlockData> c; // Yatopia - change to list
private boolean d;
public PacketPlayOutMultiBlockChange() {}
@@ -17,6 +17,8 @@ public class PacketPlayOutMultiBlockChange implements Packet<PacketListenerPlayO
public PacketPlayOutMultiBlockChange(SectionPosition sectionposition, ShortSet shortset, ChunkSection chunksection, boolean flag) {
this.a = sectionposition;
this.d = flag;
+ // Yatopia start - replace logic
+ /*
this.a(shortset.size());
int i = 0;
@@ -26,12 +28,27 @@ public class PacketPlayOutMultiBlockChange implements Packet<PacketListenerPlayO
this.b[i] = short0;
this.c[i] = (chunksection != null) ? chunksection.getType(SectionPosition.a(short0), SectionPosition.b(short0), SectionPosition.c(short0)) : Blocks.AIR.getBlockData(); // CraftBukkit - SPIGOT-6076, Mojang bug when empty chunk section notified
}
+ */
+ b = new java.util.ArrayList<>();
+ c = new java.util.ArrayList<>();
+ for (short s : shortset) {
+ b.add(s);
+ if (chunksection != null) {
+ c.add(chunksection.getType(SectionPosition.a(s), SectionPosition.b(s), SectionPosition.c(s)));
+ } else {
+ c.add(Blocks.AIR.getBlockData());
+ }
+ }
+ // Yatopia end
}
+
private void a(int i) {
+ /* // Yatopia start
this.b = new short[i];
this.c = new IBlockData[i];
+ */ // Yatopia end
}
@Override
@@ -40,6 +57,8 @@ public class PacketPlayOutMultiBlockChange implements Packet<PacketListenerPlayO
this.d = packetdataserializer.readBoolean();
int i = packetdataserializer.i();
+ // Yatopia start - replaced logic
+ /*
this.a(i);
for (int j = 0; j < this.b.length; ++j) {
@@ -48,6 +67,15 @@ public class PacketPlayOutMultiBlockChange implements Packet<PacketListenerPlayO
this.b[j] = (short) ((int) (k & 4095L));
this.c[j] = (IBlockData) Block.REGISTRY_ID.fromId((int) (k >>> 12));
}
+ */
+ b = new java.util.ArrayList<>();
+ c = new java.util.ArrayList<>();
+ for (int j = 0; j < i; j++) {
+ long k = packetdataserializer.readVarLong();
+ b.add((short) ((int) (k & 4095L)));
+ c.add(Block.REGISTRY_ID.fromId((int) (k >>> 12)));
+ }
+ // Yatopia end
}
@@ -55,10 +83,10 @@ public class PacketPlayOutMultiBlockChange implements Packet<PacketListenerPlayO
public void b(PacketDataSerializer packetdataserializer) throws IOException {
packetdataserializer.writeLong(this.a.s());
packetdataserializer.writeBoolean(this.d);
- packetdataserializer.d(this.b.length);
+ packetdataserializer.d(this.b.size()); // Yatopia
- for (int i = 0; i < this.b.length; ++i) {
- packetdataserializer.b((long) (Block.getCombinedId(this.c[i]) << 12 | this.b[i]));
+ for (int i = 0; i < this.b.size(); ++i) { // Yatopia
+ packetdataserializer.b((long) (Block.getCombinedId(this.c.get(i)) << 12 | this.b.get(i))); // Yatopia
}
}
@@ -70,11 +98,11 @@ public class PacketPlayOutMultiBlockChange implements Packet<PacketListenerPlayO
public void a(BiConsumer<BlockPosition, IBlockData> biconsumer) {
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition();
- for (int i = 0; i < this.b.length; ++i) {
- short short0 = this.b[i];
+ for (int i = 0; i < this.b.size(); ++i) { // Yatopia
+ short short0 = this.b.get(i); // Yatopia
blockposition_mutableblockposition.d(this.a.d(short0), this.a.e(short0), this.a.f(short0));
- biconsumer.accept(blockposition_mutableblockposition, this.c[i]);
+ biconsumer.accept(blockposition_mutableblockposition, this.c.get(i)); // Yatopia
}
}