perf[protocol]: max array length limit

This commit is contained in:
godotg committed 2023-12-10 22:23:13 +08:00
1 parent a406596898
commit 6a54cc7c90
7 files changed
+55 -25

No files matched your search

@@ -20,7 +20,7 @@ import com.zfoo.net.packet.EncodedPacketInfo;
import com.zfoo.net.packet.PacketService;
import com.zfoo.protocol.ProtocolManager;
import com.zfoo.protocol.buffer.ByteBufUtils;
import com.zfoo.protocol.util.MathSafeUtils;
import com.zfoo.protocol.util.IOUtils;
import com.zfoo.protocol.util.StringUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
@@ -47,7 +47,7 @@ public class JProtobufTcpCodecHandler extends ByteToMessageCodec<EncodedPacketIn
var length = in.readInt();
// 如果长度非法,则抛出异常断开连接,按照自己的使用场景指定合适的长度,防止客户端发送超大包占用带宽
if (length < 0 || length > MathSafeUtils.MAX_LENGTH) {
if (length < 0 || length > IOUtils.BYTES_PER_MB) {
throw new IllegalArgumentException(StringUtils.format("illegal packet [length:{}]", length));
}
@@ -16,7 +16,7 @@ package com.zfoo.net.handler.codec.tcp;
import com.zfoo.net.NetContext;
import com.zfoo.net.packet.EncodedPacketInfo;
import com.zfoo.net.packet.PacketService;
import com.zfoo.protocol.util.MathSafeUtils;
import com.zfoo.protocol.util.IOUtils;
import com.zfoo.protocol.util.StringUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
@@ -42,7 +42,7 @@ public class TcpCodecHandler extends ByteToMessageCodec<EncodedPacketInfo> {
var length = in.readInt();
// 如果长度非法,则抛出异常断开连接,按照自己的使用场景指定合适的长度,防止客户端发送超大包占用带宽
if (length < 0 || length > MathSafeUtils.MAX_LENGTH) {
if (length < 0 || length > IOUtils.BYTES_PER_MB) {
throw new IllegalArgumentException(StringUtils.format("illegal packet [length:{}]", length));
}
@@ -16,7 +16,7 @@ import com.zfoo.net.NetContext;
import com.zfoo.net.packet.EncodedPacketInfo;
import com.zfoo.net.packet.PacketService;
import com.zfoo.net.router.attachment.UdpAttachment;
import com.zfoo.protocol.util.MathSafeUtils;
import com.zfoo.protocol.util.IOUtils;
import com.zfoo.protocol.util.StringUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
@@ -44,7 +44,7 @@ public class UdpCodecHandler extends MessageToMessageCodec<DatagramPacket, Encod
var length = in.readInt();
// 如果长度非法,则抛出异常断开连接,按照自己的使用场景指定合适的长度,防止客户端发送超大包占用带宽
if (length < 0 || length > MathSafeUtils.MAX_LENGTH) {
if (length < 0 || length > IOUtils.BYTES_PER_MB) {
throw new IllegalArgumentException(StringUtils.format("illegal packet [length:{}]", length));
}
@@ -15,7 +15,7 @@ package com.zfoo.net.handler.codec.websocket;
import com.zfoo.net.NetContext;
import com.zfoo.net.packet.EncodedPacketInfo;
import com.zfoo.protocol.util.MathSafeUtils;
import com.zfoo.protocol.util.IOUtils;
import com.zfoo.protocol.util.StringUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
@@ -38,7 +38,7 @@ public class WebSocketCodecHandler extends MessageToMessageCodec<WebSocketFrame,
ByteBuf in = webSocketFrame.content();
var length = in.readInt();
// 如果长度非法,则抛出异常断开连接,按照自己的使用场景指定合适的长度,防止客户端发送超大包占用带宽
if (length < 0 || length > MathSafeUtils.MAX_LENGTH) {
if (length < 0 || length > IOUtils.BYTES_PER_MB) {
throw new IllegalArgumentException(StringUtils.format("illegal packet [length:{}]", length));
}
var sliceByteBuf = in.readSlice(length);