diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/nio/InboundBufferSizeException.java b/xmppserver/src/main/java/org/jivesoftware/openfire/nio/InboundBufferSizeException.java new file mode 100644 index 0000000000..8b584bdb21 --- /dev/null +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/nio/InboundBufferSizeException.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023 Ignite Realtime Foundation. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.openfire.nio; + +/** + * An Exception indicating that the inbound buffer has exceeded its limit. + */ +public class InboundBufferSizeException extends Exception { + + private static final long serialVersionUID = 1L; + + public InboundBufferSizeException() { + super(); + } + + public InboundBufferSizeException(String message, Throwable cause) { + super(message, cause); + } + + public InboundBufferSizeException(String message) { + super(message); + } + + public InboundBufferSizeException(Throwable cause) { + super(cause); + } +} diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/nio/XMLLightweightParser.java b/xmppserver/src/main/java/org/jivesoftware/openfire/nio/XMLLightweightParser.java index ccb65e24bb..5e7946b218 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/nio/XMLLightweightParser.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/nio/XMLLightweightParser.java @@ -16,7 +16,6 @@ package org.jivesoftware.openfire.nio; -import org.apache.mina.filter.codec.ProtocolDecoderException; import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.PropertyEventDispatcher; import org.jivesoftware.util.PropertyEventListener; @@ -169,14 +168,12 @@ public void read(char[] buf) throws Exception { // Check that the buffer is not bigger than 1 Megabyte. For security reasons // we will abort parsing when 1 Mega of queued chars was found. if (buffer.length() > maxBufferSize) { - // purge the local buffer / free memory - buffer = null; // set flag to inform higher level network decoders to stop reading more data maxBufferSizeExceeded = true; + // purge the local buffer / free memory + buffer = null; // processing the exception takes quite long - final ProtocolDecoderException ex = new ProtocolDecoderException("Stopped parsing never ending stanza"); // TODO throw an openfire decoder exception (not mina specific) - ex.setHexdump("(redacted hex dump of never ending stanza)"); - throw ex; + throw new InboundBufferSizeException("Stopped parsing never ending stanza"); } int readChar = buf.length; diff --git a/xmppserver/src/main/java/org/jivesoftware/openfire/nio/XMPPDecoder.java b/xmppserver/src/main/java/org/jivesoftware/openfire/nio/XMPPDecoder.java index 3c7af111d4..d02f6a8abe 100644 --- a/xmppserver/src/main/java/org/jivesoftware/openfire/nio/XMPPDecoder.java +++ b/xmppserver/src/main/java/org/jivesoftware/openfire/nio/XMPPDecoder.java @@ -43,7 +43,7 @@ protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput // exception was thrown before, avoid duplicate exception(s) // "read" and discard remaining data in.position(in.limit()); - return true; + return true; // we are empty } CharBuffer charBuffer = CharBuffer.allocate(in.capacity());