Yatopia/patches/server/0061-Fix-IndexOutOfBoundsException-when-sending-too-many-.patch
budgidiere 5b1f445951
Fix IndexOutOfBoundsException when sending too many changes
Authored-by: Ivan Pekov <ivan@mrivanplays.com>
2020-09-29 20:47:32 +03:00

125 lines
5.4 KiB
Diff

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
}
}