Skip to content

Commit

Permalink
Merge pull request #684 from ibmruntimes/openj9-staging
Browse files Browse the repository at this point in the history
Merge jdk-11.0.20+8 into 0.40.0 release
  • Loading branch information
JasonFengJ9 authored Jul 19, 2023
2 parents b427b85 + 7ef5802 commit 93bf485
Show file tree
Hide file tree
Showing 27 changed files with 675 additions and 110 deletions.
2 changes: 1 addition & 1 deletion closed/GensrcJ9JCL.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ $(J9JCL_SOURCES_DONEFILE) : \
@$(MKDIR) -p $(J9TOOLS_DIR)
$(MAKE) $(MAKE_ARGS) -C $(OPENJ9_TOPDIR)/sourcetools -f buildj9tools.mk \
BOOT_JDK=$(BOOT_JDK) \
DEST_DIR=$(call FixPath,$(J9TOOLS_DIR)) \
DEST_DIR=$(call MixedPath,$(J9TOOLS_DIR)) \
JAVA_HOME=$(BOOT_JDK) \
preprocessor
@$(ECHO) Generating J9JCL sources
Expand Down
25 changes: 7 additions & 18 deletions closed/JPP.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,17 @@ endif # OPENJ9_ENABLE_OPENJDK_METHODHANDLES
# $3 - destination subdirectory
# $4 - more options (optional)
define RunJPP
@$(ECHO) $(BOOT_JDK)/bin/java \
-cp "$(call FixPath,$(JPP_JAR))" \
$(call EchoAndRun, $(BOOT_JDK)/bin/java \
-cp "$(call MixedPath,$(JPP_JAR))" \
-Dfile.encoding=US-ASCII \
com.ibm.jpp.commandline.CommandlineBuilder \
-verdict \
-config $1 \
-baseDir "$(call FixPath,$(dir $2))" \
-baseDir "$(call MixedPath,$(dir $2))" \
-srcRoot $(notdir $2)/ \
-xml "$(call FixPath,$(OPENJ9_TOPDIR)/jcl/jpp_configuration.xml)" \
-dest "$(call FixPath,$(SUPPORT_OUTPUTDIR)$(strip $3))" \
-xml "$(call MixedPath,$(OPENJ9_TOPDIR)/jcl/jpp_configuration.xml)" \
-dest "$(call MixedPath,$(SUPPORT_OUTPUTDIR)$(strip $3))" \
-tag:define "$(subst $(SPACE),;,$(sort $(JPP_TAGS)))" \
$4
@$(BOOT_JDK)/bin/java \
-cp "$(call FixPath,$(JPP_JAR))" \
-Dfile.encoding=US-ASCII \
com.ibm.jpp.commandline.CommandlineBuilder \
-verdict \
-config $1 \
-baseDir "$(call FixPath,$(dir $2))" \
-srcRoot $(notdir $2)/ \
-xml "$(call FixPath,$(OPENJ9_TOPDIR)/jcl/jpp_configuration.xml)" \
-dest "$(call FixPath,$(SUPPORT_OUTPUTDIR)$(strip $3))" \
-tag:define "$(subst $(SPACE),;,$(sort $(JPP_TAGS)))" \
$4
$4 \
)
endef # RunJPP
7 changes: 3 additions & 4 deletions closed/OpenJ9.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ifeq (,$(wildcard $(SPEC)))
endif
include $(SPEC)
include $(TOPDIR)/make/common/MakeBase.gmk
include $(TOPDIR)/closed/JPP.gmk

ifeq (,$(BUILD_ID))
BUILD_ID := 000000
Expand Down Expand Up @@ -314,8 +315,6 @@ $(foreach file, \
$(notdir $(wildcard $(OPENJ9_TOPDIR)/buildspecs/*)), \
$(eval $(call openj9_stage_buildspec_file,$(file))))

J9TOOLS_DIR := $(SUPPORT_OUTPUTDIR)/j9tools

stage-j9 :
@$(ECHO) Staging OpenJ9 runtime in $(OUTPUTDIR)/vm
$(call openj9_copy_tree,$(OUTPUTDIR)/vm,$(OPENJ9_TOPDIR)/runtime)
Expand Down Expand Up @@ -480,13 +479,13 @@ run-preprocessors-j9 : stage-j9
+BOOT_JDK=$(BOOT_JDK) $(EXPORT_COMPILER_ENV_VARS) OPENJDK_VERSION_NUMBER_FOUR_POSITIONS=$(VERSION_NUMBER_FOUR_POSITIONS) \
$(MAKE) $(MAKE_ARGS) -C $(OUTPUTDIR)/vm -f $(OPENJ9_TOPDIR)/runtime/buildtools.mk \
BUILD_ID=$(BUILD_ID) \
DEST_DIR=$(call FixPath,$(J9TOOLS_DIR)) \
DEST_DIR=$(call MixedPath,$(J9TOOLS_DIR)) \
EXTRA_CONFIGURE_ARGS=$(OMR_EXTRA_CONFIGURE_ARGS) \
FREEMARKER_JAR="$(FREEMARKER_JAR)" \
J9VM_SHA=$(OPENJ9_SHA) \
JAVA_HOME=$(BOOT_JDK) \
OMR_DIR=$(OUTPUTDIR)/vm/omr \
SOURCETOOLS_DIR=$(call FixPath,$(OPENJ9_TOPDIR))/sourcetools \
SOURCETOOLS_DIR=$(call MixedPath,$(OPENJ9_TOPDIR))/sourcetools \
SPEC=$(OPENJ9_BUILDSPEC) \
UMA_OPTIONS_EXTRA="-buildDate $(shell date +'%Y%m%d')" \
VERSION_MAJOR=$(VERSION_FEATURE) \
Expand Down
34 changes: 34 additions & 0 deletions closed/custom/common/MakeBase.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ===========================================================================
# (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved
# ===========================================================================
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# IBM designates this particular file as subject to the "Classpath" exception
# as provided by IBM in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
# ===========================================================================

# Echo a command and then execute it.
# $1 - the command
define EchoAndRun
@ $(ECHO) $1
@ $1
endef

# On Windows, FixPath yields backslashes which can cause problems, so
# we use PATHTOOL instead for tools (like java) that support both.
ifeq ($(call isTargetOs, windows), true)
MixedPath = $(shell $(PATHTOOL) -m $1)
else
MixedPath = $1
endif
2 changes: 1 addition & 1 deletion closed/openjdk-tag.gmk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
OPENJDK_TAG := jdk-11.0.20+7
OPENJDK_TAG := jdk-11.0.20+8
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
Loading

0 comments on commit 93bf485

Please sign in to comment.