Path: blob/master/test/jdk/javax/imageio/plugins/gif/TruncatedGIFTest.java
41155 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 653202526* @summary Test verifies that we dont throw IOOBE for truncated27* GIF image28*/2930import javax.imageio.ImageIO;31import java.awt.image.BufferedImage;32import java.io.ByteArrayInputStream;33import java.io.IOException;34import javax.imageio.IIOException;3536public class TruncatedGIFTest {37public static void main(String[] args) throws IOException {38// GIFF stream with no GCT/LCT but one truncated LZW39// image block40byte[] ba = new byte[] { (byte)0x47, (byte) 0x49,41(byte)0x46, (byte)0x38, (byte)0x39, (byte)0x61,42(byte)0x01, (byte)0x00, (byte)0x01, (byte)0x00,43(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x2c,44(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,45(byte)0x01, (byte)0x00, (byte)0x01, (byte)0x00,46(byte)0x00, (byte)0x04, (byte)0x0A, (byte)0x00};4748try {49BufferedImage img = ImageIO.read(new ByteArrayInputStream(ba));50} catch (IIOException e) {51// do nothing we expect IIOException but we should not52// throw IndexOutOfBoundsException53System.out.println(e.toString());54System.out.println("Caught IIOException ignore it");55System.out.println("Test passed");56}57}58}59606162