mina自定义解码器报错?

okjjyy 发布于 08/23 20:29
阅读 18
收藏 0

自定义的mina解码器时不时就会报错,找了很久没找到原因?希望各位大佬给我排查一下,帮我理一下怎么定位这个问题一,
下是自己写的解码器

protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
        if (in.position() == in.limit())
            return false;
        //前4字节校验代码
        if (in.remaining() < 4) {
            //由于未消费字节,无需reset
            return false;
        }
        if (isPolicy(session, in))
            return false;

        in.mark();

        // 接受key
        if (in.limit() == 8) {
            for (int i = 0; i < 4; i++) {
                in.get();
            }
            byte[] keys = new byte[4];
            keys[0] = in.get();
            keys[1] = in.get();
            keys[2] = in.get();
            keys[3] = in.get();
            session.setAttribute("randomKey", keys);
            return false;
        }

        // 获得密匙
        byte[] keys = (byte[]) session.getAttribute("randomKey");
        if (keys == null) {
            in.reset();
            return false;
        }

        int dataLength = readLength1(in, keys);
        if (dataLength == -1) {
            in.reset();
            return false;
        }
        // 数据长度
        int len = in.remaining();

        // 判断长度
        if (dataLength > MNTcpConnect.MAX_DATA_LENGTH) {

            // 测试代码
            String data = "";
            {
                byte[] cc = new byte[len];
                in.get(cc);
                ByteBuffer byteBuffer = new ByteBuffer(cc);
                data = (byteBuffer.readUnsignedShort() + "   " + byteBuffer.readShort() + "    " + byteBuffer.readInt());
            }

            in.clear();
            throw new IllegalArgumentException("over max data length! length: " + dataLength + ", data:" + data);
        }
        if (dataLength > len) {
            in.reset();
            return false;
        }
        byte[] bb = new byte[dataLength];
        in.get(bb);
        // 解密数据
        ByteKit.xorBytes4(bb, keys);
        out.write(bb);
        return true;
以下是错误信息: 2019-08-21 04:51:57,928 [pool-3-thread-21256] ERRORcore.mina.MNTcpIOHandler - Error...:core.mina.MNTcpIOHandler@67a64777 org.apache.mina.filter.codec.ProtocolDecoderException: java.lang.IllegalArgumentException: over max data length! length: 1968796530, data:57386 0 1124073472 (Hexdump: 03 00 00 2F 2A E0 00 00 00 00 00 43 6F 6F 6B 69 65 3A 20 6D 73 74 73 68 61 73 68 3D 41 64 6D 69 6E 69 73 74 72 0D 0A 01 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ......) at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:262) at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:650) at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1300(DefaultIoFilterChain.java:49) at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:1141) at core.back.MNBlacklistFilter.messageReceived(MNBlacklistFilter.java:34) at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:650) at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1300(DefaultIoFilterChain.java:49) at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:1141) at org.apache.mina.core.filterchain.IoFilterAdapter.messageReceived(IoFilterAdapter.java:122) at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:650) at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireMessageReceived(DefaultIoFilterChain.java:643) at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:539) at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$1200(AbstractPollingIoProcessor.java:68) at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.process(AbstractPollingIoProcessor.java:1242) at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.process(AbstractPollingIoProcessor.java:1231) at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:683) at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalArgumentException: over max data length! length: 1968796530, data:57386 0 1124073472 at core.mina.MNProtocolDecoder.doDecode(MNProtocolDecoder.java:74) at org.apache.mina.filter.codec.CumulativeProtocolDecoder.decode(CumulativeProtocolDecoder.java:180) at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:253) ... 19 more
加载中
返回顶部
顶部