mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-14 16:18:13 +00:00
perf[protocol]: max array length limit
This commit is contained in:
1 parent
a406596898
commit
6a54cc7c90
7 files changed
+55
-25
No files matched your search
+2
-2
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user