Skip to content

Commit

Permalink
WIP: OF-2559 Removed last of MINA from XMLLightweightParser
Browse files Browse the repository at this point in the history
MINA will wrap the non-mina exception further up the chain, we were not using the hexdump feature the MINA exception added.
  • Loading branch information
viv committed Jun 29, 2023
1 parent 526cfd5 commit ccbec46
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit ccbec46

Please sign in to comment.