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

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P2
    • 1.4.0
    • Affects Version/s: 1.4.0
    • Component/s: 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);
              }
          }
      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: