mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 11:35:18 +01:00
parent
6c58f0980c
commit
435a986068
@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
|
||||
import com.github.steveice10.opennbt.NBTIO;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.github.steveice10.opennbt.tag.limiter.TagLimiter;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
@ -35,21 +35,22 @@ import java.io.DataOutput;
|
||||
|
||||
public class NBTType extends Type<CompoundTag> {
|
||||
|
||||
private static final int MAX_NBT_BYTES = 2097152; // 2mb
|
||||
private static final int MAX_NESTING_LEVEL = 512;
|
||||
|
||||
public NBTType() {
|
||||
super(CompoundTag.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag read(ByteBuf buffer) throws Exception {
|
||||
Preconditions.checkArgument(buffer.readableBytes() <= 2097152, "Cannot read NBT (got %s bytes)", buffer.readableBytes());
|
||||
|
||||
int readerIndex = buffer.readerIndex();
|
||||
byte b = buffer.readByte();
|
||||
if (b == 0) {
|
||||
return null;
|
||||
} else {
|
||||
buffer.readerIndex(readerIndex);
|
||||
return NBTIO.readTag((DataInput) new ByteBufInputStream(buffer));
|
||||
return NBTIO.readTag((DataInput) new ByteBufInputStream(buffer), TagLimiter.create(MAX_NBT_BYTES, MAX_NESTING_LEVEL));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ adventure = "4.9.3"
|
||||
gson = "2.8.8"
|
||||
fastutil = "8.5.6"
|
||||
flare = "2.0.0"
|
||||
openNBT = "2.0"
|
||||
openNBT = "2.1"
|
||||
javassist = "3.28.0-GA"
|
||||
|
||||
# Common provided
|
||||
|
Loading…
Reference in New Issue
Block a user