1 /*
   2  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6532025
  27  * @summary Test verifies that we dont throw IOOBE for truncated
  28  *          GIF image
  29  */
  30 
  31 import javax.imageio.ImageIO;
  32 import java.awt.image.BufferedImage;
  33 import java.io.ByteArrayInputStream;
  34 import java.io.IOException;
  35 import javax.imageio.IIOException;
  36 
  37 public class TruncatedGIFTest {
  38     public static void main(String[] args) throws IOException {
  39         // GIFF stream with no GCT/LCT but one truncated LZW
  40         // image block
  41         byte[] ba = new byte[] { (byte)0x47, (byte) 0x49,
  42                 (byte)0x46, (byte)0x38, (byte)0x39, (byte)0x61,
  43                 (byte)0x01, (byte)0x00, (byte)0x01, (byte)0x00,
  44                 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x2c,
  45                 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
  46                 (byte)0x01, (byte)0x00, (byte)0x01, (byte)0x00,
  47                 (byte)0x00, (byte)0x04, (byte)0x0A, (byte)0x00};
  48 
  49         try {
  50             BufferedImage img = ImageIO.read(new ByteArrayInputStream(ba));
  51         } catch (IIOException e) {
  52             // do nothing we expect IIOException but we should not
  53             // throw IndexOutOfBoundsException
  54             System.out.println(e.toString());
  55             System.out.println("Caught IIOException ignore it");
  56             System.out.println("Test passed");
  57         }
  58     }
  59 }
  60