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

ImageInputStreamImpl.readBytes(IIByteBuffer,int) throws unexpected exception

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta2
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Not verified

      Description



      Name: vpR10011 Date: 04/18/2001



      Specification of the class javax.imageio.stream.ImageInputStreamImpl says:

      "public void readBytes(IIOByteBuffer buf, int len) throws IOException
      ...
      Parameters:
          buf - an IIOByteBuffer object to be modified.
          len - the maximum number of bytes to read.
      Throws:
          IndexOutOfBoundsException - if len is negative or
          off + len is greater than b.length."

      But readBytes throws NegativeArraySizeException if len is negative.
      Furthermore, the assertion about "off + len" is not relevant for this
      method.


      To reproduce this bug run the following test:
      ---------------------test.java--------------
      import java.io.*;
      import javax.imageio.stream.*;

      public class test {
          public static void main(String[] argv) {
              byte [] bar = {1, 1, 1};
              InputStream is = (InputStream) new ByteArrayInputStream(bar);
              ImageInputStreamImpl iisI = (ImageInputStreamImpl) new MemoryCacheImageInputStream(is);
      byte [] b = new byte[10];
              IIOByteBuffer iiob = new IIOByteBuffer(b, 0, b.length);
      System.out.println("len < 0 ");
      try {
      iisI.readBytes(iiob, -1);
      } catch (IndexOutOfBoundsException e) {
                  System.out.println("Passed");
      } catch (Exception e) {
      System.out.println("Failed: unexpected exception " + e);
      }
          }
      }
      -------------------------log----------------
      % java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b60)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b60, mixed mode)
      % java test
      len < 0
      Failed: unexpected exception java.lang.NegativeArraySizeException



      This bug causes failure of the new JCK test
      api/javax_imageio/stream/ImageInputStreamImpl/index.html#readBytes


      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            dricesunw Daniel Rice (Inactive)
            Reporter:
            verapsunw Verap Verap (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: