TextLineDecoder throws an IndexOutOfBoundsException
---------------------------------------------------
Key: DIRMINA-536
URL: https://issues.apache.org/jira/browse/DIRMINA-536
Project: MINA
Issue Type: Bug
Affects Versions: 1.1.6, 1.0.9, 2.0.0-M1
Environment: All versions in any environnement
Reporter: Edouard De Oliveira
Adding the following test to the TextLineDecoderTest JUNIT test class will
raise the bug.
It's due to an incomplete match being incorrectly rewinded that causes the
IndexOutOfBoundsException
public void testSMTPDataBounds() throws Exception {
TextLineDecoder decoder = new
TextLineDecoder(Charset.forName("ISO-8859-1"),
new LineDelimiter("\r\n.\r\n"));
CharsetEncoder encoder = Charset.forName("ISO-8859-1").newEncoder();
IoSession session = new DummySession();
TestDecoderOutput out = new TestDecoderOutput();
ByteBuffer in = ByteBuffer.allocate(16).setAutoExpand(true);
in.putString("\r\n", encoder).flip().mark();
decoder.decode(session, in.reset().mark(), out);
Assert.assertEquals(0, out.getMessageQueue().size());
in.putString("Body\r\n.\r\n", encoder).flip().mark();
decoder.decode(session, in.reset().mark(), out);
Assert.assertEquals(1, out.getMessageQueue().size());
}
------
To solve the issue, a simple patch is to replace the following line in
org.apache.mina.filter.codec.textline.TextLineDecoder.java :
in.position(in.position()-matchCount);
by
in.position(Math.max(0, in.position()-matchCount));
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.