mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
net/minecraft/nbt
This commit is contained in:
parent
f2f3b06179
commit
1dd7ab9203
7 changed files with 54 additions and 69 deletions
|
@ -0,0 +1,15 @@
|
||||||
|
--- a/net/minecraft/nbt/ByteArrayTag.java
|
||||||
|
+++ b/net/minecraft/nbt/ByteArrayTag.java
|
||||||
|
@@ -1,3 +_,4 @@
|
||||||
|
+// mc-dev import
|
||||||
|
package net.minecraft.nbt;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
@@ -23,6 +_,7 @@
|
||||||
|
private static byte[] readAccounted(DataInput input, NbtAccounter accounter) throws IOException {
|
||||||
|
accounter.accountBytes(24L);
|
||||||
|
int _int = input.readInt();
|
||||||
|
+ com.google.common.base.Preconditions.checkArgument( _int < 1 << 24); // Spigot
|
||||||
|
accounter.accountBytes(1L, _int);
|
||||||
|
byte[] bytes = new byte[_int];
|
||||||
|
input.readFully(bytes);
|
|
@ -1,15 +1,15 @@
|
||||||
--- a/net/minecraft/nbt/CompoundTag.java
|
--- a/net/minecraft/nbt/CompoundTag.java
|
||||||
+++ b/net/minecraft/nbt/CompoundTag.java
|
+++ b/net/minecraft/nbt/CompoundTag.java
|
||||||
@@ -49,7 +49,7 @@
|
@@ -49,7 +_,7 @@
|
||||||
|
|
||||||
private static CompoundTag loadCompound(DataInput input, NbtAccounter tracker) throws IOException {
|
private static CompoundTag loadCompound(DataInput input, NbtAccounter nbtAccounter) throws IOException {
|
||||||
tracker.accountBytes(48L);
|
nbtAccounter.accountBytes(48L);
|
||||||
- Map<String, Tag> map = Maps.newHashMap();
|
- Map<String, Tag> map = Maps.newHashMap();
|
||||||
+ it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<String, Tag> map = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(8, 0.8f); // Paper - Reduce memory footprint of CompoundTag
|
+ it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<String, Tag> map = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(8, 0.8f); // Paper - Reduce memory footprint of CompoundTag
|
||||||
|
|
||||||
byte b;
|
byte b;
|
||||||
while ((b = input.readByte()) != 0) {
|
while ((b = input.readByte()) != 0) {
|
||||||
@@ -166,7 +166,7 @@
|
@@ -166,7 +_,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompoundTag() {
|
public CompoundTag() {
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -232,14 +232,34 @@
|
@@ -232,14 +_,34 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putUUID(String key, UUID value) {
|
public void putUUID(String key, UUID value) {
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
Tag tag = this.get(key);
|
Tag tag = this.get(key);
|
||||||
return tag != null && tag.getType() == IntArrayTag.TYPE && ((IntArrayTag)tag).getAsIntArray().length == 4;
|
return tag != null && tag.getType() == IntArrayTag.TYPE && ((IntArrayTag)tag).getAsIntArray().length == 4;
|
||||||
}
|
}
|
||||||
@@ -477,8 +497,16 @@
|
@@ -477,8 +_,16 @@
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag copy() {
|
public CompoundTag copy() {
|
|
@ -1,15 +1,15 @@
|
||||||
--- a/net/minecraft/nbt/IntArrayTag.java
|
--- a/net/minecraft/nbt/IntArrayTag.java
|
||||||
+++ b/net/minecraft/nbt/IntArrayTag.java
|
+++ b/net/minecraft/nbt/IntArrayTag.java
|
||||||
@@ -1,3 +1,4 @@
|
@@ -1,3 +_,4 @@
|
||||||
+// mc-dev import
|
+// mc-dev import
|
||||||
package net.minecraft.nbt;
|
package net.minecraft.nbt;
|
||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
@@ -24,6 +25,7 @@
|
@@ -23,6 +_,7 @@
|
||||||
private static int[] readAccounted(DataInput input, NbtAccounter tracker) throws IOException {
|
private static int[] readAccounted(DataInput input, NbtAccounter accounter) throws IOException {
|
||||||
tracker.accountBytes(24L);
|
accounter.accountBytes(24L);
|
||||||
int i = input.readInt();
|
int _int = input.readInt();
|
||||||
+ com.google.common.base.Preconditions.checkArgument( i < 1 << 24); // Spigot
|
+ com.google.common.base.Preconditions.checkArgument( _int < 1 << 24); // Spigot
|
||||||
|
accounter.accountBytes(4L, _int);
|
||||||
|
int[] ints = new int[_int];
|
||||||
|
|
||||||
tracker.accountBytes(4L, (long) i);
|
|
||||||
int[] aint = new int[i];
|
|
|
@ -1,20 +1,20 @@
|
||||||
--- a/net/minecraft/nbt/NbtIo.java
|
--- a/net/minecraft/nbt/NbtIo.java
|
||||||
+++ b/net/minecraft/nbt/NbtIo.java
|
+++ b/net/minecraft/nbt/NbtIo.java
|
||||||
@@ -1,3 +1,4 @@
|
@@ -1,3 +_,4 @@
|
||||||
+// mc-dev import
|
+// mc-dev import
|
||||||
package net.minecraft.nbt;
|
package net.minecraft.nbt;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
@@ -324,6 +325,12 @@
|
@@ -118,6 +_,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompoundTag read(DataInput input, NbtAccounter tracker) throws IOException {
|
public static CompoundTag read(DataInput input, NbtAccounter accounter) throws IOException {
|
||||||
+ // Spigot start
|
+ // Spigot start
|
||||||
+ if ( input instanceof io.netty.buffer.ByteBufInputStream )
|
+ if ( input instanceof io.netty.buffer.ByteBufInputStream )
|
||||||
+ {
|
+ {
|
||||||
+ input = new DataInputStream(new org.spigotmc.LimitStream((InputStream) input, tracker));
|
+ input = new DataInputStream(new org.spigotmc.LimitStream((InputStream) input, accounter));
|
||||||
+ }
|
+ }
|
||||||
+ // Spigot end
|
+ // Spigot end
|
||||||
Tag nbtbase = NbtIo.readUnnamedTag(input, tracker);
|
Tag unnamedTag = readUnnamedTag(input, accounter);
|
||||||
|
if (unnamedTag instanceof CompoundTag) {
|
||||||
if (nbtbase instanceof CompoundTag) {
|
return (CompoundTag)unnamedTag;
|
|
@ -1,14 +1,14 @@
|
||||||
--- a/net/minecraft/nbt/NbtUtils.java
|
--- a/net/minecraft/nbt/NbtUtils.java
|
||||||
+++ b/net/minecraft/nbt/NbtUtils.java
|
+++ b/net/minecraft/nbt/NbtUtils.java
|
||||||
@@ -149,8 +149,10 @@
|
@@ -143,8 +_,10 @@
|
||||||
if (!nbt.contains("Name", 8)) {
|
if (!tag.contains("Name", 8)) {
|
||||||
return Blocks.AIR.defaultBlockState();
|
return Blocks.AIR.defaultBlockState();
|
||||||
} else {
|
} else {
|
||||||
- ResourceLocation resourceLocation = ResourceLocation.parse(nbt.getString("Name"));
|
- ResourceLocation resourceLocation = ResourceLocation.parse(tag.getString("Name"));
|
||||||
- Optional<? extends Holder<Block>> optional = blockLookup.get(ResourceKey.create(Registries.BLOCK, resourceLocation));
|
- Optional<? extends Holder<Block>> optional = blockGetter.get(ResourceKey.create(Registries.BLOCK, resourceLocation));
|
||||||
+ // Paper start - Validate resource location
|
+ // Paper start - Validate resource location
|
||||||
+ ResourceLocation resourceLocation = ResourceLocation.tryParse(nbt.getString("Name"));
|
+ ResourceLocation resourceLocation = ResourceLocation.tryParse(tag.getString("Name"));
|
||||||
+ Optional<? extends Holder<Block>> optional = resourceLocation != null ? blockLookup.get(ResourceKey.create(Registries.BLOCK, resourceLocation)) : Optional.empty();
|
+ Optional<? extends Holder<Block>> optional = resourceLocation != null ? blockGetter.get(ResourceKey.create(Registries.BLOCK, resourceLocation)) : Optional.empty();
|
||||||
+ // Paper end - Validate resource location
|
+ // Paper end - Validate resource location
|
||||||
if (optional.isEmpty()) {
|
if (optional.isEmpty()) {
|
||||||
return Blocks.AIR.defaultBlockState();
|
return Blocks.AIR.defaultBlockState();
|
|
@ -1,14 +1,14 @@
|
||||||
--- a/net/minecraft/nbt/TagParser.java
|
--- a/net/minecraft/nbt/TagParser.java
|
||||||
+++ b/net/minecraft/nbt/TagParser.java
|
+++ b/net/minecraft/nbt/TagParser.java
|
||||||
@@ -49,6 +49,7 @@
|
@@ -49,6 +_,7 @@
|
||||||
}, CompoundTag::toString);
|
}, CompoundTag::toString);
|
||||||
public static final Codec<CompoundTag> LENIENT_CODEC = Codec.withAlternative(AS_CODEC, CompoundTag.CODEC);
|
public static final Codec<CompoundTag> LENIENT_CODEC = Codec.withAlternative(AS_CODEC, CompoundTag.CODEC);
|
||||||
private final StringReader reader;
|
private final StringReader reader;
|
||||||
+ private int depth; // Paper
|
+ private int depth; // Paper
|
||||||
|
|
||||||
public static CompoundTag parseTag(String string) throws CommandSyntaxException {
|
public static CompoundTag parseTag(String text) throws CommandSyntaxException {
|
||||||
return new TagParser(new StringReader(string)).readSingleStruct();
|
return new TagParser(new StringReader(text)).readSingleStruct();
|
||||||
@@ -159,6 +160,7 @@
|
@@ -159,6 +_,7 @@
|
||||||
|
|
||||||
public CompoundTag readStruct() throws CommandSyntaxException {
|
public CompoundTag readStruct() throws CommandSyntaxException {
|
||||||
this.expect('{');
|
this.expect('{');
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
CompoundTag compoundTag = new CompoundTag();
|
CompoundTag compoundTag = new CompoundTag();
|
||||||
this.reader.skipWhitespace();
|
this.reader.skipWhitespace();
|
||||||
|
|
||||||
@@ -182,6 +184,7 @@
|
@@ -182,6 +_,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.expect('}');
|
this.expect('}');
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
return compoundTag;
|
return compoundTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,6 +194,7 @@
|
@@ -191,6 +_,7 @@
|
||||||
if (!this.reader.canRead()) {
|
if (!this.reader.canRead()) {
|
||||||
throw ERROR_EXPECTED_VALUE.createWithContext(this.reader);
|
throw ERROR_EXPECTED_VALUE.createWithContext(this.reader);
|
||||||
} else {
|
} else {
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
ListTag listTag = new ListTag();
|
ListTag listTag = new ListTag();
|
||||||
TagType<?> tagType = null;
|
TagType<?> tagType = null;
|
||||||
|
|
||||||
@@ -216,6 +220,7 @@
|
@@ -216,6 +_,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.expect(']');
|
this.expect(']');
|
||||||
|
@ -40,30 +40,15 @@
|
||||||
return listTag;
|
return listTag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,11 +258,11 @@
|
@@ -287,5 +_,11 @@
|
||||||
}
|
private void expect(char expected) throws CommandSyntaxException {
|
||||||
|
|
||||||
if (typeReader == ByteTag.TYPE) {
|
|
||||||
- list.add((T)((NumericTag)tag).getAsByte());
|
|
||||||
+ list.add((T)(Byte)((NumericTag)tag).getAsByte()); // Paper - decompile fix
|
|
||||||
} else if (typeReader == LongTag.TYPE) {
|
|
||||||
- list.add((T)((NumericTag)tag).getAsLong());
|
|
||||||
+ list.add((T)(Long)((NumericTag)tag).getAsLong()); // Paper - decompile fix
|
|
||||||
} else {
|
|
||||||
- list.add((T)((NumericTag)tag).getAsInt());
|
|
||||||
+ list.add((T)(Integer)((NumericTag)tag).getAsInt()); // Paper - decompile fix
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.hasElementSeparator()) {
|
|
||||||
@@ -288,4 +293,11 @@
|
|
||||||
this.reader.skipWhitespace();
|
this.reader.skipWhitespace();
|
||||||
this.reader.expect(c);
|
this.reader.expect(expected);
|
||||||
}
|
+ }
|
||||||
+
|
|
||||||
+ private void increaseDepth() throws CommandSyntaxException {
|
+ private void increaseDepth() throws CommandSyntaxException {
|
||||||
+ this.depth++;
|
+ this.depth++;
|
||||||
+ if (this.depth > 512) {
|
+ if (this.depth > 512) {
|
||||||
+ throw new io.papermc.paper.brigadier.TagParseCommandSyntaxException("NBT tag is too complex, depth > 512");
|
+ throw new io.papermc.paper.brigadier.TagParseCommandSyntaxException("NBT tag is too complex, depth > 512");
|
||||||
+ }
|
+ }
|
||||||
+ }
|
}
|
||||||
}
|
}
|
|
@ -1,15 +0,0 @@
|
||||||
--- a/net/minecraft/nbt/ByteArrayTag.java
|
|
||||||
+++ b/net/minecraft/nbt/ByteArrayTag.java
|
|
||||||
@@ -1,3 +1,4 @@
|
|
||||||
+// mc-dev import
|
|
||||||
package net.minecraft.nbt;
|
|
||||||
|
|
||||||
import java.io.DataInput;
|
|
||||||
@@ -24,6 +25,7 @@
|
|
||||||
private static byte[] readAccounted(DataInput input, NbtAccounter tracker) throws IOException {
|
|
||||||
tracker.accountBytes(24L);
|
|
||||||
int i = input.readInt();
|
|
||||||
+ com.google.common.base.Preconditions.checkArgument( i < 1 << 24); // Spigot
|
|
||||||
|
|
||||||
tracker.accountBytes(1L, (long) i);
|
|
||||||
byte[] abyte = new byte[i];
|
|
Loading…
Reference in a new issue