#3028: Add protocol level string length limits
This commit is contained in:
parent
e95da11115
commit
3d701fbe0e
@ -33,16 +33,27 @@ public abstract class DefinedPacket
|
||||
|
||||
public static String readString(ByteBuf buf)
|
||||
{
|
||||
int len = readVarInt( buf );
|
||||
if ( len > Short.MAX_VALUE )
|
||||
return readString( buf, Short.MAX_VALUE );
|
||||
}
|
||||
|
||||
public static String readString(ByteBuf buf, int maxLen)
|
||||
{
|
||||
throw new OverflowPacketException( String.format( "Cannot receive string longer than Short.MAX_VALUE (got %s characters)", len ) );
|
||||
int len = readVarInt( buf );
|
||||
if ( len > maxLen * 4 )
|
||||
{
|
||||
throw new OverflowPacketException( String.format( "Cannot receive string longer than %d (got %d bytes)", maxLen * 4, len ) );
|
||||
}
|
||||
|
||||
byte[] b = new byte[ len ];
|
||||
buf.readBytes( b );
|
||||
|
||||
return new String( b, Charsets.UTF_8 );
|
||||
String s = new String( b, Charsets.UTF_8 );
|
||||
if ( s.length() > maxLen )
|
||||
{
|
||||
throw new OverflowPacketException( String.format( "Cannot receive string longer than %d (got %d characters)", maxLen, s.length() ) );
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static void writeArray(byte[] b, ByteBuf buf)
|
||||
|
@ -24,7 +24,7 @@ public class LoginRequest extends DefinedPacket
|
||||
@Override
|
||||
public void read(ByteBuf buf)
|
||||
{
|
||||
data = readString( buf );
|
||||
data = readString( buf, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user