mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 07:20:04 -04:00
ByteBuffers: check String length against max length
This commit is contained in:
parent
ee37e092cb
commit
9f19b460fb
@ -101,6 +101,10 @@ 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));
|
||||
}
|
||||
return new String(readBytes(readVarInt()), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@ -152,7 +156,8 @@ public class InByteBuffer {
|
||||
int byteCount = 0;
|
||||
int result = 0;
|
||||
byte read;
|
||||
do {
|
||||
do
|
||||
{
|
||||
read = readByte();
|
||||
result |= (read & 0x7F) << (7 * byteCount);
|
||||
byteCount++;
|
||||
|
@ -85,6 +85,9 @@ public class OutByteBuffer {
|
||||
}
|
||||
|
||||
public void writeString(String string) {
|
||||
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));
|
||||
}
|
||||
writeVarInt(string.length());
|
||||
writeBytes(string.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
@ -147,7 +150,8 @@ public class OutByteBuffer {
|
||||
|
||||
public void writeVarInt(int value) {
|
||||
// thanks https://wiki.vg/Protocol#VarInt_and_VarLong
|
||||
do {
|
||||
do
|
||||
{
|
||||
byte temp = (byte) (value & 0x7F);
|
||||
value >>>= 7;
|
||||
if (value != 0) {
|
||||
@ -160,7 +164,8 @@ public class OutByteBuffer {
|
||||
public void prefixVarInt(int value) {
|
||||
int count = 0;
|
||||
// thanks https://wiki.vg/Protocol#VarInt_and_VarLong
|
||||
do {
|
||||
do
|
||||
{
|
||||
byte temp = (byte) (value & 0x7F);
|
||||
value >>>= 7;
|
||||
if (value != 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user