Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Raise limit on JoinGame NBT reading to 2MiB.
This is required for particularly large mod packs (think All of Fabric 3 for instance).
Dieser Commit ist enthalten in:
Ursprung
fcffccf0d8
Commit
03e9fa79d6
@ -16,6 +16,8 @@ import io.netty.handler.codec.CorruptedFrameException;
|
|||||||
import io.netty.handler.codec.DecoderException;
|
import io.netty.handler.codec.DecoderException;
|
||||||
import io.netty.handler.codec.EncoderException;
|
import io.netty.handler.codec.EncoderException;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -227,11 +229,12 @@ public enum ProtocolUtils {
|
|||||||
/**
|
/**
|
||||||
* Reads a {@link net.kyori.adventure.nbt.CompoundBinaryTag} from the {@code buf}.
|
* Reads a {@link net.kyori.adventure.nbt.CompoundBinaryTag} from the {@code buf}.
|
||||||
* @param buf the buffer to read from
|
* @param buf the buffer to read from
|
||||||
|
* @param reader the NBT reader to use
|
||||||
* @return {@link net.kyori.adventure.nbt.CompoundBinaryTag} the CompoundTag from the buffer
|
* @return {@link net.kyori.adventure.nbt.CompoundBinaryTag} the CompoundTag from the buffer
|
||||||
*/
|
*/
|
||||||
public static CompoundBinaryTag readCompoundTag(ByteBuf buf) {
|
public static CompoundBinaryTag readCompoundTag(ByteBuf buf, BinaryTagIO.Reader reader) {
|
||||||
try {
|
try {
|
||||||
return BinaryTagIO.readDataInput(new ByteBufInputStream(buf));
|
return reader.read((DataInput) new ByteBufInputStream(buf));
|
||||||
} catch (IOException thrown) {
|
} catch (IOException thrown) {
|
||||||
throw new DecoderException(
|
throw new DecoderException(
|
||||||
"Unable to parse NBT CompoundTag, full error: " + thrown.getMessage());
|
"Unable to parse NBT CompoundTag, full error: " + thrown.getMessage());
|
||||||
@ -245,7 +248,7 @@ public enum ProtocolUtils {
|
|||||||
*/
|
*/
|
||||||
public static void writeCompoundTag(ByteBuf buf, CompoundBinaryTag compoundTag) {
|
public static void writeCompoundTag(ByteBuf buf, CompoundBinaryTag compoundTag) {
|
||||||
try {
|
try {
|
||||||
BinaryTagIO.writeDataOutput(compoundTag, new ByteBufOutputStream(buf));
|
BinaryTagIO.writer().write(compoundTag, (DataOutput) new ByteBufOutputStream(buf));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new EncoderException("Unable to encode NBT CompoundTag");
|
throw new EncoderException("Unable to encode NBT CompoundTag");
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import com.velocitypowered.proxy.connection.registry.DimensionInfo;
|
|||||||
import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
|
import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
|
||||||
import com.velocitypowered.proxy.protocol.*;
|
import com.velocitypowered.proxy.protocol.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.kyori.adventure.nbt.BinaryTagIO;
|
||||||
import net.kyori.adventure.nbt.BinaryTagTypes;
|
import net.kyori.adventure.nbt.BinaryTagTypes;
|
||||||
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||||
import net.kyori.adventure.nbt.ListBinaryTag;
|
import net.kyori.adventure.nbt.ListBinaryTag;
|
||||||
@ -15,6 +16,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
public class JoinGame implements MinecraftPacket {
|
public class JoinGame implements MinecraftPacket {
|
||||||
|
|
||||||
|
private static final BinaryTagIO.Reader JOINGAME_READER = BinaryTagIO.reader(2 * 1024 * 1024);
|
||||||
private int entityId;
|
private int entityId;
|
||||||
private short gamemode;
|
private short gamemode;
|
||||||
private int dimension;
|
private int dimension;
|
||||||
@ -178,7 +180,7 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
this.previousGamemode = buf.readByte();
|
this.previousGamemode = buf.readByte();
|
||||||
ImmutableSet<String> levelNames = ImmutableSet.copyOf(ProtocolUtils.readStringArray(buf));
|
ImmutableSet<String> levelNames = ImmutableSet.copyOf(ProtocolUtils.readStringArray(buf));
|
||||||
CompoundBinaryTag registryContainer = ProtocolUtils.readCompoundTag(buf);
|
CompoundBinaryTag registryContainer = ProtocolUtils.readCompoundTag(buf, JOINGAME_READER);
|
||||||
ListBinaryTag dimensionRegistryContainer = null;
|
ListBinaryTag dimensionRegistryContainer = null;
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
|
||||||
dimensionRegistryContainer = registryContainer.getCompound("minecraft:dimension_type")
|
dimensionRegistryContainer = registryContainer.getCompound("minecraft:dimension_type")
|
||||||
@ -192,7 +194,7 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
DimensionRegistry.fromGameData(dimensionRegistryContainer, version);
|
DimensionRegistry.fromGameData(dimensionRegistryContainer, version);
|
||||||
this.dimensionRegistry = new DimensionRegistry(readData, levelNames);
|
this.dimensionRegistry = new DimensionRegistry(readData, levelNames);
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
|
||||||
CompoundBinaryTag currentDimDataTag = ProtocolUtils.readCompoundTag(buf);
|
CompoundBinaryTag currentDimDataTag = ProtocolUtils.readCompoundTag(buf, JOINGAME_READER);
|
||||||
dimensionIdentifier = ProtocolUtils.readString(buf);
|
dimensionIdentifier = ProtocolUtils.readString(buf);
|
||||||
this.currentDimensionData = DimensionData.decodeBaseCompoundTag(currentDimDataTag, version)
|
this.currentDimensionData = DimensionData.decodeBaseCompoundTag(currentDimDataTag, version)
|
||||||
.annotateWith(dimensionIdentifier, null);
|
.annotateWith(dimensionIdentifier, null);
|
||||||
|
@ -7,6 +7,7 @@ import com.velocitypowered.proxy.connection.registry.DimensionInfo;
|
|||||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.kyori.adventure.nbt.BinaryTagIO;
|
||||||
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||||
|
|
||||||
public class Respawn implements MinecraftPacket {
|
public class Respawn implements MinecraftPacket {
|
||||||
@ -116,7 +117,7 @@ public class Respawn implements MinecraftPacket {
|
|||||||
String levelName = null;
|
String levelName = null;
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
|
||||||
CompoundBinaryTag dimDataTag = ProtocolUtils.readCompoundTag(buf);
|
CompoundBinaryTag dimDataTag = ProtocolUtils.readCompoundTag(buf, BinaryTagIO.reader());
|
||||||
dimensionIdentifier = ProtocolUtils.readString(buf);
|
dimensionIdentifier = ProtocolUtils.readString(buf);
|
||||||
this.currentDimensionData = DimensionData.decodeBaseCompoundTag(dimDataTag, version)
|
this.currentDimensionData = DimensionData.decodeBaseCompoundTag(dimDataTag, version)
|
||||||
.annotateWith(dimensionIdentifier, null);
|
.annotateWith(dimensionIdentifier, null);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren