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

CachedOutputStream#writeCacheTo(StringBuilder, int) fails with StringIndexOutOfBoundsException

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.1.1
    • Component/s: Core
    • Labels:
      None
    • Estimated Complexity:
      Novice

      Description

      public void writeCacheTo(StringBuilder out, int limit) throws IOException {
      ...
      if ((count + x) > limit)

      { x = count - limit; <<< this has to be: x = limit - count; }

      out.append(new String(bytes, 0, x));
      count += x;
      ...
      }

      If limit is reached x becomes negative and String construction fails with

      java.lang.StringIndexOutOfBoundsException: String index out of range: -784
      at java.lang.String.checkBounds(String.java:368)
      at java.lang.String.<init>(String.java:457)
      at org.apache.cxf.io.CachedOutputStream.writeCacheTo(CachedOutputStream.java:272)

        Attachments

          Activity

            People

            • Assignee:
              bmargulies Benson Margulies
              Reporter:
              axelviii Axel Dehning
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: