Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit d9b9b1f

Browse files
authored
Merge pull request #46
* Set string max length to Short.MAX_VALUE (32767), Fix multibyte strin…
1 parent 4fbb472 commit d9b9b1f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main/java/com/github/steveice10/packetlib/codec/BasePacketCodecHelper.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,21 @@ public long readVarLong(ByteBuf buf) {
141141
}
142142

143143
public String readString(ByteBuf buf) {
144-
return this.readString(buf, Integer.MAX_VALUE);
144+
return this.readString(buf, Short.MAX_VALUE);
145145
}
146146

147147
@Override
148148
public String readString(ByteBuf buf, int maxLength) {
149149
int length = this.readVarInt(buf);
150-
if (length > maxLength) {
150+
if (length > maxLength * 3) {
151+
throw new IllegalArgumentException("String buffer is longer than maximum allowed length");
152+
}
153+
String string = (String) buf.readCharSequence(length, StandardCharsets.UTF_8);
154+
if (string.length() > maxLength) {
151155
throw new IllegalArgumentException("String is longer than maximum allowed length");
152156
}
153157

154-
return (String) buf.readCharSequence(length, StandardCharsets.UTF_8);
158+
return string;
155159
}
156160

157161
@Override

0 commit comments

Comments
 (0)