Skip to content

Commit

Permalink
Merge master jdk-11.0.20+8 into openj9-staging
Browse files Browse the repository at this point in the history
Signed-off-by: J9 Build <j9build@ca.ibm.com>
  • Loading branch information
j9build committed Jul 18, 2023
2 parents 1575f9f + 6f922ea commit 6f29104
Show file tree
Hide file tree
Showing 18 changed files with 582 additions and 84 deletions.
2 changes: 1 addition & 1 deletion make/autoconf/version-numbers
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ DEFAULT_VERSION_DATE=2023-07-18
DEFAULT_VERSION_CLASSFILE_MAJOR=55 # "`$EXPR $DEFAULT_VERSION_FEATURE + 44`"
DEFAULT_VERSION_CLASSFILE_MINOR=0
DEFAULT_ACCEPTABLE_BOOT_VERSIONS="10 11"
DEFAULT_PROMOTED_VERSION_PRE=ea
DEFAULT_PROMOTED_VERSION_PRE=

LAUNCHER_NAME=openjdk
PRODUCT_NAME=OpenJDK
Expand Down
11 changes: 6 additions & 5 deletions src/java.base/share/classes/java/util/jar/JarFile.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -153,8 +153,6 @@ class JarFile extends ZipFile {
private static final boolean MULTI_RELEASE_ENABLED;
private static final boolean MULTI_RELEASE_FORCED;
private static final ThreadLocal<Boolean> isInitializing = new ThreadLocal<>();
// The maximum size of array to allocate. Some VMs reserve some header words in an array.
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;

private SoftReference<Manifest> manRef;
private JarEntry manEntry;
Expand Down Expand Up @@ -807,8 +805,11 @@ private void initializeVerifier() {
private byte[] getBytes(ZipEntry ze) throws IOException {
try (InputStream is = super.getInputStream(ze)) {
long uncompressedSize = ze.getSize();
if (uncompressedSize > MAX_ARRAY_SIZE) {
throw new IOException("Unsupported size: " + uncompressedSize);
if (uncompressedSize > SignatureFileVerifier.MAX_SIG_FILE_SIZE) {
throw new IOException("Unsupported size: " + uncompressedSize +
" for JarEntry " + ze.getName() +
". Allowed max size: " +
SignatureFileVerifier.MAX_SIG_FILE_SIZE + " bytes");
}
int len = (int)uncompressedSize;
int bytesRead;
Expand Down
129 changes: 129 additions & 0 deletions src/java.base/share/classes/java/util/zip/ZipFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
import jdk.internal.ref.CleanerFactory;
import jdk.internal.vm.annotation.Stable;
import sun.nio.cs.UTF_8;
import sun.security.action.GetBooleanAction;
import java.security.AccessController;

import static java.util.zip.ZipConstants64.*;
import static java.util.zip.ZipUtils.*;
Expand Down Expand Up @@ -117,6 +119,13 @@ class ZipFile implements ZipConstants, Closeable {
*/
public static final int OPEN_READ = 0x1;

/**
* Flag which specifies whether the validation of the Zip64 extra
* fields should be disabled
*/
private static final boolean disableZip64ExtraFieldValidation =
AccessController.doPrivileged
(new GetBooleanAction("jdk.util.zip.disableZip64ExtraFieldValidation"));
/**
* Mode flag to open a zip file and mark it for deletion. The file will be
* deleted some time between the moment that it is opened and the moment
Expand Down Expand Up @@ -1211,6 +1220,119 @@ private int addEntry(int index, int hash, int next, int pos) {
entries[index++] = pos;
return index;
}

/**
* Validate the Zip64 Extra block fields
* @param startingOffset Extra Field starting offset within the CEN
* @param extraFieldLen Length of this Extra field
* @throws ZipException If an error occurs validating the Zip64 Extra
* block
*/
private void checkExtraFields(int cenPos, int startingOffset,
int extraFieldLen) throws ZipException {
// Extra field Length cannot exceed 65,535 bytes per the PKWare
// APP.note 4.4.11
if (extraFieldLen > 0xFFFF) {
zerror("invalid extra field length");
}
// CEN Offset where this Extra field ends
int extraEndOffset = startingOffset + extraFieldLen;
if (extraEndOffset > cen.length) {
zerror("Invalid CEN header (extra data field size too long)");
}
int currentOffset = startingOffset;
while (currentOffset < extraEndOffset) {
int tag = get16(cen, currentOffset);
currentOffset += Short.BYTES;

int tagBlockSize = get16(cen, currentOffset);
int tagBlockEndingOffset = currentOffset + tagBlockSize;

// The ending offset for this tag block should not go past the
// offset for the end of the extra field
if (tagBlockEndingOffset > extraEndOffset) {
zerror("Invalid CEN header (invalid zip64 extra data field size)");
}
currentOffset += Short.BYTES;

if (tag == ZIP64_EXTID) {
// Get the compressed size;
long csize = CENSIZ(cen, cenPos);
// Get the uncompressed size;
long size = CENLEN(cen, cenPos);
checkZip64ExtraFieldValues(currentOffset, tagBlockSize,
csize, size);
}
currentOffset += tagBlockSize;
}
}

/**
* Validate the Zip64 Extended Information Extra Field (0x0001) block
* size and that the uncompressed size and compressed size field
* values are not negative.
* Note: As we do not use the LOC offset or Starting disk number
* field value we will not validate them
* @param off the starting offset for the Zip64 field value
* @param blockSize the size of the Zip64 Extended Extra Field
* @param csize CEN header compressed size value
* @param size CEN header uncompressed size value
* @throws ZipException if an error occurs
*/
private void checkZip64ExtraFieldValues(int off, int blockSize, long csize,
long size)
throws ZipException {
byte[] cen = this.cen;
// Validate the Zip64 Extended Information Extra Field (0x0001)
// length.
if (!isZip64ExtBlockSizeValid(blockSize)) {
zerror("Invalid CEN header (invalid zip64 extra data field size)");
}
// Check the uncompressed size is not negative
// Note we do not need to check blockSize is >= 8 as
// we know its length is at least 8 from the call to
// isZip64ExtBlockSizeValid()
if ((size == ZIP64_MAGICVAL)) {
if(get64(cen, off) < 0) {
zerror("Invalid zip64 extra block size value");
}
}
// Check the compressed size is not negative
if ((csize == ZIP64_MAGICVAL) && (blockSize >= 16)) {
if (get64(cen, off + 8) < 0) {
zerror("Invalid zip64 extra block compressed size value");
}
}
}

/**
* Validate the size and contents of a Zip64 extended information field
* The order of the Zip64 fields is fixed, but the fields MUST
* only appear if the corresponding LOC or CEN field is set to 0xFFFF:
* or 0xFFFFFFFF:
* Uncompressed Size - 8 bytes
* Compressed Size - 8 bytes
* LOC Header offset - 8 bytes
* Disk Start Number - 4 bytes
* See PKWare APP.Note Section 4.5.3 for more details
*
* @param blockSize the Zip64 Extended Information Extra Field size
* @return true if the extra block size is valid; false otherwise
*/
private static boolean isZip64ExtBlockSizeValid(int blockSize) {
/*
* As the fields must appear in order, the block size indicates which
* fields to expect:
* 8 - uncompressed size
* 16 - uncompressed size, compressed size
* 24 - uncompressed size, compressed sise, LOC Header offset
* 28 - uncompressed size, compressed sise, LOC Header offset,
* and Disk start number
*/
int i = blockSize;
return i == 8 || i == 16 || i == 24 || i == 28 ? true : false;
}

private int getEntryHash(int index) { return entries[index]; }
private int getEntryNext(int index) { return entries[index + 1]; }
private int getEntryPos(int index) { return entries[index + 2]; }
Expand Down Expand Up @@ -1571,6 +1693,13 @@ private void initCEN(int knownTotal, ZipCoder zc) throws IOException {
} else {
checkEncoding(zc, cen, pos + CENHDR, nlen);
}
if (elen > 0 && !disableZip64ExtraFieldValidation) {
long extraStartingOffset = pos + CENHDR + nlen;
if ((int)extraStartingOffset != extraStartingOffset) {
zerror("invalid CEN header (bad extra offset)");
}
checkExtraFields(pos, (int)extraStartingOffset, elen);
}
// Record the CEN offset and the name hash in our hash cell.
hash = hashN(cen, pos + CENHDR, nlen);
hsh = (hash & 0x7fffffff) % tablelen;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -50,6 +50,7 @@
import java.util.jar.JarFile;
import java.util.jar.Manifest;

import sun.security.action.GetIntegerAction;
import sun.security.jca.Providers;
import sun.security.pkcs.PKCS7;
import sun.security.pkcs.SignerInfo;
Expand Down Expand Up @@ -95,6 +96,12 @@ public class SignatureFileVerifier {
/** ConstraintsParameters for checking disabled algorithms */
private JarConstraintsParameters params;

// the maximum allowed size in bytes for the signature-related files
public static final int MAX_SIG_FILE_SIZE = initializeMaxSigFileSize();

// The maximum size of array to allocate. Some VMs reserve some header words in an array.
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;

/**
* Create the named SignatureFileVerifier.
*
Expand Down Expand Up @@ -838,4 +845,24 @@ void updateSigners(CodeSigner[] newSigners,
signerCache.add(cachedSigners);
signers.put(name, cachedSigners);
}

private static int initializeMaxSigFileSize() {
/*
* System property "jdk.jar.maxSignatureFileSize" used to configure
* the maximum allowed number of bytes for the signature-related files
* in a JAR file.
*/
Integer tmp = GetIntegerAction.privilegedGetProperty(
"jdk.jar.maxSignatureFileSize", 8000000);
if (tmp < 0 || tmp > MAX_ARRAY_SIZE) {
if (debug != null) {
debug.println("Default signature file size 8000000 bytes " +
"is used as the specified size for the " +
"jdk.jar.maxSignatureFileSize system property " +
"is out of range: " + tmp);
}
tmp = 8000000;
}
return tmp;
}
}
3 changes: 2 additions & 1 deletion src/java.base/share/conf/security/java.security
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,8 @@ jdk.tls.legacyAlgorithms= \
# Note: This property is currently used by OpenJDK's JSSE implementation. It
# is not guaranteed to be examined and used by other implementations.
#
jdk.tls.keyLimits=AES/GCM/NoPadding KeyUpdate 2^37
jdk.tls.keyLimits=AES/GCM/NoPadding KeyUpdate 2^37, \
ChaCha20-Poly1305 KeyUpdate 2^37

#
# Cryptographic Jurisdiction Policy defaults
Expand Down
8 changes: 4 additions & 4 deletions src/java.base/unix/classes/sun/nio/fs/UnixUriUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ static Path fromUri(UnixFileSystem fs, URI uri) {
int pos = 0;
while (pos < len) {
char c = p.charAt(pos++);
if ((c == '/') && (pos < len) && (p.charAt(pos) == '/')) {
// skip redundant slashes
continue;
}
byte b;
if (c == '%') {
assert (pos+2) <= len;
Expand All @@ -91,6 +87,10 @@ static Path fromUri(UnixFileSystem fs, URI uri) {
throw new IllegalArgumentException("Bad escape");
b = (byte)c;
}
if (b == '/' && rlen > 0 && result[rlen-1] == '/') {
// skip redundant slashes
continue;
}
result[rlen++] = b;
}
if (rlen != result.length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,18 @@ public void load(InputStream input, Class<?> resourceBase) throws
* <code>new URL(synthFile, path)</code>. Refer to
* <a href="doc-files/synthFileFormat.html">Synth File Format</a> for more
* information.
* <p>
* Whilst this API may be safe for loading local resources that are
* delivered with a {@code LookAndFeel} or application, and so have an
* equal level of trust with application code, using it to load from
* remote resources, particularly any which may have a lower level of
* trust, is strongly discouraged.
* The alternative mechanisms to load styles from an {@code InputStream}
* {@linkplain #load(InputStream, Class)}
* using resources co-located with the application or by providing a
* {@code SynthStyleFactory} to
* {@linkplain #setStyleFactory setStyleFactory(SynthStyleFactory)}
* are preferred.
*
* @param url the <code>URL</code> to load the set of
* <code>SynthStyle</code> from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ <h1><a id="file">File Format</a></h1>
<p>
This example loads the look and feel from an input stream, using
the specified class as the resource base to resolve paths.
</p>
<p>
It is also possible to load a look and feel from an arbitrary URL
as in the following example.
</p>
Expand All @@ -94,6 +96,11 @@ <h1><a id="file">File Format</a></h1>
<li>Remote JAR file, e.g.
<code>jar:http://host/synth-laf.jar!/laf.xml</code></li>
</ul>
<p>Note: Synth's file format allows for the definition of code to be executed.
Loading any code from a remote location should be used only
with extreme caution from a trusted source over a secure connection.
It is strongly discouraged for an application or a LookAndFeel to do so.
</p>
<p>
While the DTD for synth is specified, the parser is not validating.
Parsing will fail only if a necessary attribute is not
Expand Down
Loading

0 comments on commit 6f29104

Please sign in to comment.