Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-4227

AttachmentDeserializerTest contains buggy code for reading an InputStream.

    XMLWordPrintableJSON

Details

    • Novice

    Description

      Browsing through the CXF code, I stumbled over the following in AttachmentDeserializerTest, method testCXF3383():

      for (int x = 1; x < 50; x++) {
          String cid = "1882f79d-e20a-4b36-a222-7a75518cf395-" + x + "@cxf.apache.org";
          DataSource ds = AttachmentUtil.getAttachmentDataSource(cid, message.getAttachments());
          byte bts[] = new byte[1024];
                  
          InputStream ins = ds.getInputStream();
          int count = ins.read(bts, 0, bts.length);
          int sz = ins.read(bts, count, bts.length - count);
          while (sz != -1) {
              sz = ins.read(bts, count, bts.length - count);
          }
          assertEquals(x + 1, count);
      }
      

      I think some "count += sz" has been forgotten. Details:

      • The while-loop does nothing to change the test result.
      • Endless loop, should "ins" ever deliver 1025 bytes or more.
      • (If "ins" is 0 bytes, then count will be -1.)
      • The fix is obvious, I'll attach a patch.

      The problem does not show as long as "ins" contains less than 1024 bytes and all its content is delivered with the first read operation. So no functional impairment, just code hygiene.

      Attachments

        1. AttachmentDeserializerTest.patch
          1 kB
          Andreas Krüger

        Activity

          People

            ffang Freeman Yue Fang
            andreas.krueger@dv-ratio.com Andreas Krüger
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

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