Skip to content

Commit

Permalink
Increase some limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Alemiz112 committed Jun 11, 2024
1 parent a8a052f commit cf9c990
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,14 @@ public void writeByteBuf(ByteBuf buffer, ByteBuf toWrite) {
}

public String readString(ByteBuf buffer) {
return this.readStringMaxLen(buffer, this.encodingSettings.maxStringLength());
}

@Override
public String readStringMaxLen(ByteBuf buffer, int maxLength) {
int length = VarInts.readUnsignedInt(buffer);
checkArgument(this.encodingSettings.maxStringLength() <= 0 || length <= this.encodingSettings.maxStringLength(),
"Tried to read %s bytes but maximum is %s", length, this.encodingSettings.maxStringLength());
checkArgument(maxLength <= 0 || length <= maxLength,
"Tried to read %s bytes but maximum is %s", length, maxLength);
return (String) buffer.readCharSequence(length, StandardCharsets.UTF_8);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ default <T> void writeArray(ByteBuf buffer, Collection<T> array, TriConsumer<Byt

String readString(ByteBuf buffer);

String readStringMaxLen(ByteBuf buffer, int maxLength);

void writeString(ByteBuf buffer, String string);

UUID readUuid(ByteBuf buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public void serialize(ByteBuf buffer, BedrockCodecHelper helper, PurchaseReceipt

@Override
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, PurchaseReceiptPacket packet) {
helper.readArray(buffer, packet.getReceipts(), helper::readString);
helper.readArray(buffer, packet.getReceipts(), buf -> helper.readStringMaxLen(buf, 1024 * 128)); // This json is usually bigger than other strings
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SerializedSkin readSkin(ByteBuf buffer) {
this.readArray(buffer, animations, ByteBuf::readIntLE, (b, h) -> this.readAnimationData(b));

ImageData capeData = this.readImage(buffer, ImageData.SINGLE_SKIN_SIZE);
String geometryData = this.readString(buffer);
String geometryData = this.readStringMaxLen(buffer, 1024 * 256); // Allow larger geometry data
String animationData = this.readString(buffer);
boolean premium = buffer.readBoolean();
boolean persona = buffer.readBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public SerializedSkin readSkin(ByteBuf buffer) {
this.readArray(buffer, animations, ByteBuf::readIntLE, (b, h) -> this.readAnimationData(b));

ImageData capeData = this.readImage(buffer, ImageData.SINGLE_SKIN_SIZE);
String geometryData = this.readString(buffer);
String geometryData = this.readStringMaxLen(buffer, 1024 * 256); // Allow larger geometry data
String animationData = this.readString(buffer);
boolean premium = buffer.readBoolean();
boolean persona = buffer.readBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public SerializedSkin readSkin(ByteBuf buffer) {
this.readArray(buffer, animations, ByteBuf::readIntLE, (b, h) -> this.readAnimationData(b));

ImageData capeData = this.readImage(buffer, ImageData.SINGLE_SKIN_SIZE);
String geometryData = this.readString(buffer);
String geometryData = this.readStringMaxLen(buffer, 1024 * 256); // Allow larger geometry data
String animationData = this.readString(buffer);
boolean premium = buffer.readBoolean();
boolean persona = buffer.readBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public SerializedSkin readSkin(ByteBuf buffer) {
this.readArray(buffer, animations, ByteBuf::readIntLE, (b, h) -> this.readAnimationData(b));

ImageData capeData = this.readImage(buffer, ImageData.SINGLE_SKIN_SIZE);
String geometryData = this.readString(buffer);
String geometryData = this.readStringMaxLen(buffer, 1024 * 256); // Allow larger geometry data
String geometryDataEngineVersion = this.readString(buffer);
String animationData = this.readString(buffer);
String capeId = this.readString(buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void serialize(ByteBuf buffer, BedrockCodecHelper helper, SubChunkRequest
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, SubChunkRequestPacket packet) {
packet.setDimension(VarInts.readInt(buffer));
packet.setSubChunkPosition(helper.readVector3i(buffer));
helper.readArray(buffer, packet.getPositionOffsets(), ByteBuf::readIntLE, this::readSubChunkOffset, 2048); // Somehow client sometimes requests over 1000 sub chunks
helper.readArray(buffer, packet.getPositionOffsets(), ByteBuf::readIntLE, this::readSubChunkOffset, 3072); // Somehow client sometimes requests over 1000 sub chunks
}

protected void writeSubChunkOffset(ByteBuf buffer, Vector3i offsetPosition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.netty.buffer.ByteBuf;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.v534.serializer.AddPlayerSerializer_v534;
import org.cloudburstmc.protocol.bedrock.codec.v534.serializer.UpdateAbilitiesSerializer_v534;
import org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket;
import org.cloudburstmc.protocol.common.util.VarInts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public SerializedSkin readSkin(ByteBuf buffer) {
this.readArray(buffer, animations, ByteBuf::readIntLE, (b, h) -> this.readAnimationData(b));

ImageData capeData = this.readImage(buffer, ImageData.SINGLE_SKIN_SIZE);
String geometryData = this.readString(buffer);
String geometryData = this.readStringMaxLen(buffer, 1024 * 256); // Allow larger geometry data
String geometryDataEngineVersion = this.readString(buffer);
String animationData = this.readString(buffer);
String capeId = this.readString(buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.netty.buffer.ByteBuf;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.BedrockPacketSerializer;
import org.cloudburstmc.protocol.bedrock.data.TrimMaterial;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.cloudburstmc.protocol.common.util.TypeMap;
import org.cloudburstmc.protocol.common.util.VarInts;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down

0 comments on commit cf9c990

Please sign in to comment.