Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/imageio/plugins/png/MaxLengthKeywordReadTest.java
41155 views
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 8195841
27
* @summary Test verifies that PNGImageReader doesn't allow creation of
28
* non null terminated keywords consuming full length where they
29
* should be null terminated
30
* @run main MaxLengthKeywordReadTest
31
*/
32
33
import java.io.ByteArrayInputStream;
34
import java.io.IOException;
35
import java.util.Base64;
36
import java.util.Iterator;
37
import javax.imageio.IIOException;
38
import javax.imageio.ImageIO;
39
import javax.imageio.ImageReader;
40
import javax.imageio.stream.ImageInputStream;
41
42
public class MaxLengthKeywordReadTest {
43
// PNG image stream having non null terminated keyword of length 80
44
// in tEXt chunk
45
private static String inputImageBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAA" +
46
"ABCAAAAAA6fptVAAAAUXRFWHRBdXRob3JlZEF1dGhvcmVkQXV0aG9yZWRBdXRob" +
47
"3JlZEF1dGhvcmVkQXV0aG9yZWRBdXRob3JlZEF1dGhvcmVkQXV0aG9yZWRBdXRo" +
48
"b3JlZAAhn0sLAAAACklEQVR4XmP4DwABAQEAJwnd2gAAAABJRU5ErkJggg==";
49
50
public static void main(String[] args) throws IOException {
51
byte[] inputBytes = Base64.getDecoder().decode(inputImageBase64);
52
ByteArrayInputStream bais = new ByteArrayInputStream(inputBytes);
53
ImageInputStream input = ImageIO.createImageInputStream(bais);
54
Iterator iter = ImageIO.getImageReaders(input);
55
ImageReader reader = (ImageReader) iter.next();
56
reader.setInput(input, false, false);
57
try {
58
reader.read(0, reader.getDefaultReadParam());
59
} catch (IIOException e) {
60
// we expect it to throw IIOException
61
if (e.getCause().getMessage() !=
62
"Found non null terminated string") {
63
throw new RuntimeException("Test failed. Did not get " +
64
"expected IIOException");
65
}
66
}
67
}
68
}
69
70