Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/imageio/plugins/png/PngNegativeDimensionTest.java
41155 views
1
/*
2
* Copyright (c) 2017, 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 8190512
27
* @summary Test verifies whether PNGImageReader throws IIOException with proper
28
* message or not when IHDR chunk contains negative value for width
29
* and height.
30
* @run main PngNegativeDimensionTest
31
*/
32
33
import java.io.ByteArrayInputStream;
34
import java.io.InputStream;
35
import java.util.Base64;
36
import javax.imageio.ImageIO;
37
38
public class PngNegativeDimensionTest {
39
40
private static String negativeWidthString = "iVBORw0KGgoAAAANSUhEUoAAAAEAA"
41
+ "AABCAAAAAA6fptVAAAACklEQVQYV2P4DwABAQEAWk1v8QAAAABJRU5ErkJgggo=";
42
43
private static String negativeHeightString = "iVBORw0KGgoAAAANSUhEUgAAAAGAA"
44
+ "AABCAAAAAA6fptVAAAACklEQVQYV2P4DwABAQEAWk1v8QAAAABJRU5ErkJgggo=";
45
46
private static InputStream input;
47
private static Boolean failed = false;
48
49
public static void main(String[] args) {
50
// Create InputStream
51
byte[] inputBytes = Base64.getDecoder().decode(negativeWidthString);
52
input = new ByteArrayInputStream(inputBytes);
53
// Attempt to read PNG with negative IHDR width
54
readNegativeIHDRWidthImage();
55
56
inputBytes = Base64.getDecoder().decode(negativeHeightString);
57
input = new ByteArrayInputStream(inputBytes);
58
// Attempt to read PNG with negative IHDR height
59
readNegativeIHDRHeightImage();
60
61
if (failed) {
62
throw new RuntimeException("Test didnt throw proper IIOException"
63
+ " when IHDR width/height is negative");
64
}
65
}
66
67
private static void readNegativeIHDRWidthImage() {
68
try {
69
ImageIO.read(input);
70
} catch (Exception e) {
71
/*
72
* We expect the test case to throw IIOException with message
73
* under root cause as "Image width <= 0!". If it throws
74
* any other message or exception test will fail.
75
*/
76
Throwable cause = e.getCause();
77
if (cause == null ||
78
(!(cause.getMessage().equals("Image width <= 0!"))))
79
{
80
failed = true;
81
}
82
}
83
}
84
85
private static void readNegativeIHDRHeightImage() {
86
try {
87
ImageIO.read(input);
88
} catch (Exception e) {
89
/*
90
* We expect the test case to throw IIOException with message
91
* under root cause as "Image height <= 0!". If it throws
92
* any other message or exception test will fail.
93
*/
94
Throwable cause = e.getCause();
95
if (cause == null ||
96
(!(cause.getMessage().equals("Image height <= 0!"))))
97
{
98
failed = true;
99
}
100
}
101
}
102
}
103
104
105