Uploaded image for project: 'MINA'
  1. MINA
  2. DIRMINA-536

TextLineDecoder throws an IndexOutOfBoundsException

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0.9, 1.1.6, 2.0.0-M1
    • 1.0.10, 1.1.7, 2.0.0-M2
    • Filter
    • None
    • All versions in any environnement

    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

          ted_kods Edouard De Oliveira created issue -
          ted_kods Edouard De Oliveira made changes -
          Field Original Value New Value
          Component/s Filter [ 12311385 ]
          mheath Mike Heath made changes -
          Fix Version/s 2.0.0-M2 [ 12312861 ]
          elihusmails Mark Webb added a comment -

          Where does the class TestDecoderOutput come from?

          elihusmails Mark Webb added a comment - Where does the class TestDecoderOutput come from?

          It's an internal class of org.apache.mina.filter.codec.textline.TextLineDecoderTest which can be found in the core/src/test directory
          of the mina 1.1.6 archive for example.

          ted_kods Edouard De Oliveira added a comment - It's an internal class of org.apache.mina.filter.codec.textline.TextLineDecoderTest which can be found in the core/src/test directory of the mina 1.1.6 archive for example.
          trustin Trustin Lee made changes -
          Fix Version/s 1.1.7 [ 12312994 ]
          Fix Version/s 1.0.10 [ 12312993 ]
          Assignee Trustin Lee [ trustin ]
          trustin Trustin Lee added a comment -

          Fixed as you suggested. Please close this issue if it resolves your problem.

          trustin Trustin Lee added a comment - Fixed as you suggested. Please close this issue if it resolves your problem.
          trustin Trustin Lee made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Resolved [ 5 ]

          The fix is working as expected

          but it seems that the JUnit test has not been added to org.apache.mina.filter.codec.textline.TextLineDecoderTest in 1.1 branch
          Is it intentionnal ?

          ted_kods Edouard De Oliveira added a comment - The fix is working as expected but it seems that the JUnit test has not been added to org.apache.mina.filter.codec.textline.TextLineDecoderTest in 1.1 branch Is it intentionnal ?
          trustin Trustin Lee added a comment -

          Yes, 1.x is purely under maintenance mode. I was lazy to backport the test cases to both 1.0 and 1.1.

          trustin Trustin Lee added a comment - Yes, 1.x is purely under maintenance mode. I was lazy to backport the test cases to both 1.0 and 1.1.

          Fix ok

          ted_kods Edouard De Oliveira added a comment - Fix ok
          ted_kods Edouard De Oliveira made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

          People

            trustin Trustin Lee
            ted_kods Edouard De Oliveira
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 0.25h
                0.25h
                Remaining:
                Remaining Estimate - 0.25h
                0.25h
                Logged:
                Time Spent - Not Specified
                Not Specified