Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/tools/jarsigner/LargeJarEntry.java
41152 views
1
/*
2
* Copyright (c) 2006, 2012, 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 6405538 6474350
27
* @summary Make sure jar files with large entries (more than max heap size)
28
* can be signed
29
* @modules jdk.jartool/sun.security.tools.jarsigner
30
* @run main/othervm -Xmx16m LargeJarEntry
31
* @author Sean Mullan
32
*/
33
34
import java.io.File;
35
import java.io.FileOutputStream;
36
import java.util.jar.JarEntry;
37
import java.util.jar.JarOutputStream;
38
import java.util.zip.CRC32;
39
40
public class LargeJarEntry {
41
42
public static void main(String[] args) throws Exception {
43
44
String srcDir = System.getProperty("test.src", ".");
45
String keystore = srcDir + "/JarSigning.keystore";
46
String jarName = "largeJarEntry.jar";
47
48
// Set java.io.tmpdir to the current working dir (see 6474350)
49
System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));
50
51
// first, create jar file with 8M uncompressed entry
52
// note, we set the max heap size to 8M in @run tag above
53
byte[] bytes = new byte[1000000];
54
CRC32 crc = new CRC32();
55
for (int i=0; i<8; i++) {
56
crc.update(bytes);
57
}
58
JarEntry je = new JarEntry("large");
59
je.setSize(8000000l);
60
je.setMethod(JarEntry.STORED);
61
je.setCrc(crc.getValue());
62
File file = new File(jarName);
63
FileOutputStream os = new FileOutputStream(file);
64
JarOutputStream jos = new JarOutputStream(os);
65
jos.setMethod(JarEntry.STORED);
66
jos.putNextEntry(je);
67
for (int i=0; i<8; i++) {
68
jos.write(bytes, 0, bytes.length);
69
}
70
jos.close();
71
72
String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
73
jarName, "b" };
74
// now, try to sign it
75
try {
76
sun.security.tools.jarsigner.Main.main(jsArgs);
77
} catch (OutOfMemoryError err) {
78
throw new Exception("Test failed with OutOfMemoryError", err);
79
} finally {
80
// remove jar file
81
file.delete();
82
}
83
}
84
}
85
86