network: fix string reading length check

This commit is contained in:
Bixilon 2021-02-28 13:32:07 +01:00
parent aded63eba9
commit 42d9c9b592
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -109,11 +109,11 @@ public class InByteBuffer {
}
public String readString() {
byte[] data = readBytes(readVarInt());
if (data.length > ProtocolDefinition.STRING_MAX_LEN) {
throw new IllegalArgumentException(String.format("String max string length exceeded %d > %d", data.length, ProtocolDefinition.STRING_MAX_LEN));
String string = new String(readBytes(readVarInt()), StandardCharsets.UTF_8);
if (string.length() > ProtocolDefinition.STRING_MAX_LEN) {
throw new IllegalArgumentException(String.format("String max string length exceeded %d > %d", string.length(), ProtocolDefinition.STRING_MAX_LEN));
}
return new String(data, StandardCharsets.UTF_8);
return string;
}
public long readVarLong() {