A char can be 3 bytes (#843)

BungeeCord reference: b5365dcba7
This commit is contained in:
Outfluencer 2022-08-20 04:45:58 +02:00 committed by GitHub
parent 4b33d5fb8a
commit 47cd9faf65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -185,9 +185,9 @@ public enum ProtocolUtils {
private static String readString(ByteBuf buf, int cap, int length) {
checkFrame(length >= 0, "Got a negative-length string (%s)", length);
// `cap` is interpreted as a UTF-8 character length. To cover the full Unicode plane, we must
// consider the length of a UTF-8 character, which can be up to 4 bytes. We do an initial
// consider the length of a UTF-8 character, which can be up to 3 bytes. We do an initial
// sanity check and then check again to make sure our optimistic guess was good.
checkFrame(length <= cap * 4, "Bad string size (got %s, maximum is %s)", length, cap);
checkFrame(length <= cap * 3, "Bad string size (got %s, maximum is %s)", length, cap);
checkFrame(buf.isReadable(length),
"Trying to read a string that is too long (wanted %s, only have %s)", length,
buf.readableBytes());