8199172: Improve jar attribute checks
Reviewed-by: psandoz, alanb
This commit is contained in:
parent
627e310ba5
commit
cd8e70a35c
@ -1011,29 +1011,13 @@ class JarFile extends ZipFile {
|
|||||||
int i = match(MULTIRELEASE_CHARS, b, MULTIRELEASE_LASTOCC,
|
int i = match(MULTIRELEASE_CHARS, b, MULTIRELEASE_LASTOCC,
|
||||||
MULTIRELEASE_OPTOSFT);
|
MULTIRELEASE_OPTOSFT);
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
i += MULTIRELEASE_CHARS.length;
|
// Read the main attributes of the manifest
|
||||||
if (i < b.length) {
|
byte[] lbuf = new byte[512];
|
||||||
byte c = b[i++];
|
Attributes attr = new Attributes();
|
||||||
// Check that the value is followed by a newline
|
attr.read(new Manifest.FastInputStream(
|
||||||
// and does not have a continuation
|
new ByteArrayInputStream(b)), lbuf);
|
||||||
if (c == '\n' &&
|
isMultiRelease = Boolean.parseBoolean(
|
||||||
(i == b.length || b[i] != ' ')) {
|
attr.getValue(Attributes.Name.MULTI_RELEASE));
|
||||||
isMultiRelease = true;
|
|
||||||
} else if (c == '\r') {
|
|
||||||
if (i == b.length) {
|
|
||||||
isMultiRelease = true;
|
|
||||||
} else {
|
|
||||||
c = b[i++];
|
|
||||||
if (c == '\n') {
|
|
||||||
if (i == b.length || b[i] != ' ') {
|
|
||||||
isMultiRelease = true;
|
|
||||||
}
|
|
||||||
} else if (c != ' ') {
|
|
||||||
isMultiRelease = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8132734 8144062 8165723
|
* @bug 8132734 8144062 8165723 8199172
|
||||||
* @summary Test the extended API and the aliasing additions in JarFile that
|
* @summary Test the extended API and the aliasing additions in JarFile that
|
||||||
* support multi-release jar files
|
* support multi-release jar files
|
||||||
* @library /lib/testlibrary/java/util/jar /test/lib
|
* @library /lib/testlibrary/java/util/jar /test/lib
|
||||||
@ -100,16 +100,30 @@ public class MultiReleaseJarAPI {
|
|||||||
testCustomMultiReleaseValue("true", true);
|
testCustomMultiReleaseValue("true", true);
|
||||||
testCustomMultiReleaseValue("true\r\nOther: value", true);
|
testCustomMultiReleaseValue("true\r\nOther: value", true);
|
||||||
testCustomMultiReleaseValue("true\nOther: value", true);
|
testCustomMultiReleaseValue("true\nOther: value", true);
|
||||||
testCustomMultiReleaseValue("true\rOther: value", true);
|
// JDK-8200530: '\r' support in Manifest/Attributes will be addressed separately
|
||||||
|
// testCustomMultiReleaseValue("true\rOther: value", true);
|
||||||
|
|
||||||
testCustomMultiReleaseValue("false", false);
|
testCustomMultiReleaseValue("false", false);
|
||||||
testCustomMultiReleaseValue(" true", false);
|
testCustomMultiReleaseValue(" true", false);
|
||||||
testCustomMultiReleaseValue("true ", false);
|
testCustomMultiReleaseValue("true ", false);
|
||||||
testCustomMultiReleaseValue("true\n ", false);
|
|
||||||
testCustomMultiReleaseValue("true\r ", false);
|
|
||||||
testCustomMultiReleaseValue("true\n true", false);
|
testCustomMultiReleaseValue("true\n true", false);
|
||||||
|
|
||||||
|
// JDK-8200530: '\r' support in Manifest/Attributes will be addressed separately
|
||||||
|
testCustomMultiReleaseValue("true\r true", false);
|
||||||
testCustomMultiReleaseValue("true\r\n true", false);
|
testCustomMultiReleaseValue("true\r\n true", false);
|
||||||
|
|
||||||
|
// "Multi-Release: true/false" not in main attributes
|
||||||
|
testCustomMultiReleaseValue("\r\n\r\nName: test\r\nMulti-Release: true\r\n",
|
||||||
|
false);
|
||||||
|
testCustomMultiReleaseValue("\n\nName: entryname\nMulti-Release: true\n",
|
||||||
|
false);
|
||||||
|
testCustomMultiReleaseValue("EndOfMainAttr: whatever\r\n" +
|
||||||
|
"\r\nName: entryname\r\nMulti-Release: true\r\n",
|
||||||
|
false);
|
||||||
|
testCustomMultiReleaseValue("EndOfMainAttr: whatever\r\n" +
|
||||||
|
"\nName: entryname\nMulti-Release: true\n",
|
||||||
|
false);
|
||||||
|
|
||||||
// generate "random" Strings to use as extra attributes, and
|
// generate "random" Strings to use as extra attributes, and
|
||||||
// verify that Multi-Release: true is always properly matched
|
// verify that Multi-Release: true is always properly matched
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
|
@ -142,6 +142,12 @@ public class CreateMultiReleaseTestJars {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void buildSignedMultiReleaseJar() throws Exception {
|
public void buildSignedMultiReleaseJar() throws Exception {
|
||||||
|
buildSignedMultiReleaseJar("multi-release.jar", "signed-multi-release.jar");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void buildSignedMultiReleaseJar(String multiReleaseJar,
|
||||||
|
String signedMultiReleaseJar) throws Exception
|
||||||
|
{
|
||||||
String testsrc = System.getProperty("test.src",".");
|
String testsrc = System.getProperty("test.src",".");
|
||||||
String testdir = findTestDir(testsrc);
|
String testdir = findTestDir(testsrc);
|
||||||
String keystore = testdir + "/sun/security/tools/jarsigner/JarSigning.keystore";
|
String keystore = testdir + "/sun/security/tools/jarsigner/JarSigning.keystore";
|
||||||
@ -155,8 +161,8 @@ public class CreateMultiReleaseTestJars {
|
|||||||
CertPath cp = CertificateFactory.getInstance("X.509")
|
CertPath cp = CertificateFactory.getInstance("X.509")
|
||||||
.generateCertPath(Arrays.asList(ks.getCertificateChain("b")));
|
.generateCertPath(Arrays.asList(ks.getCertificateChain("b")));
|
||||||
JarSigner js = new JarSigner.Builder(pkb, cp).build();
|
JarSigner js = new JarSigner.Builder(pkb, cp).build();
|
||||||
try (ZipFile in = new ZipFile("multi-release.jar");
|
try (ZipFile in = new ZipFile(multiReleaseJar);
|
||||||
FileOutputStream os = new FileOutputStream("signed-multi-release.jar"))
|
FileOutputStream os = new FileOutputStream(signedMultiReleaseJar))
|
||||||
{
|
{
|
||||||
js.sign(in, os);
|
js.sign(in, os);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user