Skip to content

Commit

Permalink
Fix banner crash exploit
Browse files Browse the repository at this point in the history
  • Loading branch information
Samsuik committed Aug 18, 2023
1 parent 7deb984 commit fe13ae6
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion patches/server/0014-Fix-some-creative-exploits.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 4adef32d2418f5c1e1891346b655557e5850790e Mon Sep 17 00:00:00 2001
From 04c6b026af4aad5996388baee237f473969290cb Mon Sep 17 00:00:00 2001
From: Samsuik <[email protected]>
Date: Tue, 9 May 2023 16:43:24 +0100
Subject: [PATCH] Fix some creative exploits
Expand Down Expand Up @@ -260,6 +260,56 @@ index 863e9d8e9..0b3fe9930 100644
entityliving.heal((float) j, RegainReason.MAGIC); // CraftBukkit
}

diff --git a/src/main/java/net/minecraft/server/TileEntityBanner.java b/src/main/java/net/minecraft/server/TileEntityBanner.java
index aa5ad2ef0..8778e1ce9 100644
--- a/src/main/java/net/minecraft/server/TileEntityBanner.java
+++ b/src/main/java/net/minecraft/server/TileEntityBanner.java
@@ -19,11 +19,7 @@ public class TileEntityBanner extends TileEntity {
NBTTagCompound nbttagcompound = itemstack.getTag().getCompound("BlockEntityTag");

if (nbttagcompound.hasKey("Patterns")) {
- this.patterns = (NBTTagList) nbttagcompound.getList("Patterns", 10).clone();
- // CraftBukkit start
- while (this.patterns.size() > 20) {
- this.patterns.a(20); // PAIL Rename remove
- }
+ this.patterns = loadPatternsFromCompound(nbttagcompound); // Blossom - avoid o(n^2) removal of unnecessary patterns
// CraftBukkit end
}

@@ -42,6 +38,18 @@ public class TileEntityBanner extends TileEntity {
this.g = true;
}

+ // Blossom start
+ private NBTTagList loadPatternsFromCompound(NBTTagCompound nbttagcompound) {
+ NBTTagList list = nbttagcompound.getList("Patterns", 10);
+ NBTTagList patterns = new NBTTagList();
+ int min = Math.min(list.size(), 20);
+ for (int i = 0; i < min; ++i) {
+ patterns.add(list.get(i));
+ }
+ return patterns;
+ }
+ // Blossom end
+
public void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
a(nbttagcompound, this.color, this.patterns);
@@ -58,12 +66,7 @@ public class TileEntityBanner extends TileEntity {
public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
this.color = nbttagcompound.getInt("Base");
- this.patterns = nbttagcompound.getList("Patterns", 10);
- // CraftBukkit start
- while (this.patterns.size() > 20) {
- this.patterns.a(20); // PAIL Rename remove
- }
- // CraftBukkit end
+ this.patterns = loadPatternsFromCompound(nbttagcompound); // Blossom - avoid o(n^2) removal of unnecessary patterns
this.h = null;
this.i = null;
this.j = null;
diff --git a/src/main/java/net/minecraft/server/TileEntitySkull.java b/src/main/java/net/minecraft/server/TileEntitySkull.java
index 58014c5f1..51b7cc90a 100644
--- a/src/main/java/net/minecraft/server/TileEntitySkull.java
Expand Down

0 comments on commit fe13ae6

Please sign in to comment.