1 /* 2 * Copyright (c) 2018, 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 8191073 27 * @summary Test verifies that when user tries to read image data from a 28 * tables-only image input stream it should through IIOException 29 * instead of throwing any other exception as per specification. 30 * @run main JpegTablesOnlyReadTest 31 */ 32 33 import java.io.ByteArrayInputStream; 34 import java.io.IOException; 35 import java.io.InputStream; 36 import java.util.Base64; 37 import javax.imageio.IIOException; 38 import javax.imageio.ImageIO; 39 40 public class JpegTablesOnlyReadTest { 41 // JPEG input stream containing tables-only image 42 private static String inputImageBase64 = "/9j/4IAQSkZJRgABAQEASABIAAD" 43 + "/2wBDAFA3PEY8MlBGQUZaVVBfeMiCeG5uePWvuZHI//////////////////////" 44 + "//////////////////////////////2wBDAVVaWnhpeOuCguv//////////////" 45 + "///////////////////////////////////////////////////////////wAAR" 46 + "CAAgACADASIAAhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAAECA//EACUQAQA" 47 + "CAAUDBAMAAAAAAAAAAAEAAhESITGxQXKSA2Fi0SIyUf/EABYBAQEBAAAAAAAAAA" 48 + "AAAAAAAAABA//EABcRAQEBAQAAAAAAAAAAAAAAAAEAESH/2gAMAwEAAhEDEQA/A" 49 + "Nf2VW2OKaWTqnRhl97eb9wrs91uWPEBUX+EtmrssvvbzfuJWjVG2tg1svLLtgJ0" 50 + "Uxwmd96d5zE7tVdnutyxm5JVoo0u6rpXHdWLP8PU8WIjtRuvVZN96d5zDP8AD1P" 51 + "Fhre1Apc/Ida4RAdv/9k="; 52 53 public static void main(String[] args) throws IOException { 54 byte[] inputBytes = Base64.getDecoder().decode(inputImageBase64); 55 InputStream in = new ByteArrayInputStream(inputBytes); 56 57 // Read tables-only JPEG image 58 try { 59 ImageIO.read(in); 60 } catch (IIOException e) { 61 /* 62 * do nothing we expect it to throw IIOException if it throws 63 * any other exception test will fail. 64 */ 65 } 66 } 67 } 68