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

JPEG reader doesn't detect out-of-range image index when reading

XMLWordPrintable

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

        The following test program reads image 0 and 1 from a given JPEG file.
      Image 0 is read O.K., but the attempt to read the non-existent image at
      index 1 fails with an IIOException from the underlying library. Instead,
      the EOF condition should be detected and an IndexOutOfBoundsException
      should be thrown.

      import java.io.File;
      import java.io.IOException;
      import javax.imageio.ImageIO;
      import javax.imageio.ImageReader;
      import javax.imageio.stream.ImageInputStream;
      import com.sun.imageio.plugins.jpeg.JPEGImageReader;

      public class JPEGMultiImage {

          public static void main(String[] args) throws IOException {
              File f = new File(args[0]);
              if (!f.exists()) {
                  throw new RuntimeException("No such file: " + filename);
              }

              // Try reading image 0, all should be O.K.
              ImageReader reader = null;
              try {
                  ImageInputStream iis = ImageIO.createImageInputStream(f);
                  reader = new JPEGImageReader(null);
                  reader.setInput(iis, true);
                  reader.read(0);
              } catch (IOException ioe0) {
                  throw new RuntimeException("Got exception reading image 0: " +
                                             ioe0);
              }

              // Now try reading non-existing image 1
              try {
                  reader.read(1);
              } catch (IOException ioe1) {
                  throw new RuntimeException("Got exception reading image 1: " +
                                             ioe1);
              }
          }
      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: