Details
Description
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));
Attachments
Activity
Edouard De Oliveira
created issue -
Edouard De Oliveira
made changes -
Field | Original Value | New Value |
---|---|---|
Component/s | Filter [ 12311385 ] |
Mike Heath
made changes -
Fix Version/s | 2.0.0-M2 [ 12312861 ] |
Trustin Lee
made changes -
Fix Version/s | 1.1.7 [ 12312994 ] | |
Fix Version/s | 1.0.10 [ 12312993 ] | |
Assignee | Trustin Lee [ trustin ] |
Trustin Lee
made changes -
Resolution | Fixed [ 1 ] | |
Status | Open [ 1 ] | Resolved [ 5 ] |
Edouard De Oliveira
made changes -
Status | Resolved [ 5 ] | Closed [ 6 ] |
Where does the class TestDecoderOutput come from?