Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4422328

MemoryCacheImageOutputStream can't flush or close

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.4.0
    • client-libs
    • beta
    • generic
    • generic



      Name: boT120536 Date: 03/06/2001


      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)

      [ This bug is in EA2, however the EA bug report
      page has options for submitting only EA1 IIO
      bug reports. ]

      Flushing or closing a MemoryCacheImageOutputStream invokes
      MemoryCache.writeToStream(), where this code (line 114
      in MemoryCache.java) throws an IndexOutOfBounds:

              if ((pos >= length) || (pos+len>=length)) {
                  throw new IndexOutOfBoundsException("Argument out of cache");

      It's an off-by-one error: the >= tests on the first
      line should be > tests.

      Example Code


      // Compile and run with:
      // javac -classpath .:imageio-1_0-ea2/imageio.jar MemoryCacheLengthBug.java
      // java -classpath .:imageio-1_0-ea2/imageio.jar MemoryCacheLengthBug

      // Produces:
      // java.lang.IndexOutOfBoundsException: Argument out of cache
      // at javax.imageio.stream.MemoryCache.writeToStream(MemoryCache.java:115)
      // at javax.imageio.stream.MemoryCacheImageOutputStream.flushBefore(MemoryCacheImageOutputStream.java:127)
      // at javax.imageio.stream.ImageInputStreamImpl.flush(ImageInputStreamImpl.java:714)
      // at MemoryCacheLengthBug.main(MemoryCacheLengthBug.java:16)

      import java.io.FileOutputStream;
      import javax.imageio.stream.MemoryCacheImageOutputStream;

      class MemoryCacheLengthBug {

          static public void main( String [] args ) {
              try {
                  MemoryCacheImageOutputStream stream =
                     new MemoryCacheImageOutputStream( new FileOutputStream( "test.txt" ) );
                  stream.write( 0 ); // or write anything, for that matter
                  stream.flush();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }


      (Review ID: 115807)
      ======================================================================

            dricesunw Daniel Rice (Inactive)
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: