Skip to content

Commit b7e431f

Browse files
authored
Merge pull request #239 from ibmruntimes/openj9-staging
Merge jdk-17.0.8+7 into 0.40.0 release
2 parents 2f3d502 + bf3d2d7 commit b7e431f

File tree

28 files changed

+676
-111
lines changed

28 files changed

+676
-111
lines changed

closed/GensrcJ9JCL.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ $(J9JCL_SOURCES_DONEFILE) : \
6161
@$(MKDIR) -p $(J9TOOLS_DIR)
6262
$(MAKE) $(MAKE_ARGS) -C $(OPENJ9_TOPDIR)/sourcetools -f buildj9tools.mk \
6363
BOOT_JDK=$(BOOT_JDK) \
64-
DEST_DIR=$(call FixPath,$(J9TOOLS_DIR)) \
64+
DEST_DIR=$(call MixedPath,$(J9TOOLS_DIR)) \
6565
JAVA_HOME=$(BOOT_JDK) \
6666
preprocessor
6767
@$(ECHO) Generating J9JCL sources

closed/JPP.gmk

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,17 @@ endif # OPENJ9_ENABLE_INLINE_TYPES
3636
# $3 - destination subdirectory
3737
# $4 - more options (optional)
3838
define RunJPP
39-
@$(ECHO) $(BOOT_JDK)/bin/java \
40-
-cp "$(call FixPath,$(JPP_JAR))" \
39+
$(call EchoAndRun, $(BOOT_JDK)/bin/java \
40+
-cp "$(call MixedPath,$(JPP_JAR))" \
4141
-Dfile.encoding=US-ASCII \
4242
com.ibm.jpp.commandline.CommandlineBuilder \
4343
-verdict \
4444
-config $1 \
45-
-baseDir "$(call FixPath,$(dir $2))" \
45+
-baseDir "$(call MixedPath,$(dir $2))" \
4646
-srcRoot $(notdir $2)/ \
47-
-xml "$(call FixPath,$(OPENJ9_TOPDIR)/jcl/jpp_configuration.xml)" \
48-
-dest "$(call FixPath,$(SUPPORT_OUTPUTDIR)$(strip $3))" \
47+
-xml "$(call MixedPath,$(OPENJ9_TOPDIR)/jcl/jpp_configuration.xml)" \
48+
-dest "$(call MixedPath,$(SUPPORT_OUTPUTDIR)$(strip $3))" \
4949
-tag:define "$(subst $(SPACE),;,$(sort $(JPP_TAGS)))" \
50-
$4
51-
@$(BOOT_JDK)/bin/java \
52-
-cp "$(call FixPath,$(JPP_JAR))" \
53-
-Dfile.encoding=US-ASCII \
54-
com.ibm.jpp.commandline.CommandlineBuilder \
55-
-verdict \
56-
-config $1 \
57-
-baseDir "$(call FixPath,$(dir $2))" \
58-
-srcRoot $(notdir $2)/ \
59-
-xml "$(call FixPath,$(OPENJ9_TOPDIR)/jcl/jpp_configuration.xml)" \
60-
-dest "$(call FixPath,$(SUPPORT_OUTPUTDIR)$(strip $3))" \
61-
-tag:define "$(subst $(SPACE),;,$(sort $(JPP_TAGS)))" \
62-
$4
50+
$4 \
51+
)
6352
endef # RunJPP

closed/OpenJ9.gmk

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ifeq (,$(wildcard $(SPEC)))
2727
endif
2828
include $(SPEC)
2929
include $(TOPDIR)/make/common/MakeBase.gmk
30+
include $(TOPDIR)/closed/JPP.gmk
3031

3132
ifeq (,$(BUILD_ID))
3233
BUILD_ID := 000000
@@ -318,8 +319,6 @@ $(foreach file, \
318319
$(notdir $(wildcard $(OPENJ9_TOPDIR)/buildspecs/*)), \
319320
$(eval $(call openj9_stage_buildspec_file,$(file))))
320321

321-
J9TOOLS_DIR := $(SUPPORT_OUTPUTDIR)/j9tools
322-
323322
stage-j9 :
324323
@$(ECHO) Staging OpenJ9 runtime in $(OUTPUTDIR)/vm
325324
$(call openj9_copy_tree,$(OUTPUTDIR)/vm,$(OPENJ9_TOPDIR)/runtime)
@@ -484,13 +483,13 @@ run-preprocessors-j9 : stage-j9
484483
+BOOT_JDK=$(BOOT_JDK) $(EXPORT_COMPILER_ENV_VARS) OPENJDK_VERSION_NUMBER_FOUR_POSITIONS=$(VERSION_NUMBER_FOUR_POSITIONS) \
485484
$(MAKE) $(MAKE_ARGS) -C $(OUTPUTDIR)/vm -f $(OPENJ9_TOPDIR)/runtime/buildtools.mk \
486485
BUILD_ID=$(BUILD_ID) \
487-
DEST_DIR=$(call FixPath,$(J9TOOLS_DIR)) \
486+
DEST_DIR=$(call MixedPath,$(J9TOOLS_DIR)) \
488487
EXTRA_CONFIGURE_ARGS=$(OMR_EXTRA_CONFIGURE_ARGS) \
489488
FREEMARKER_JAR="$(FREEMARKER_JAR)" \
490489
J9VM_SHA=$(OPENJ9_SHA) \
491490
JAVA_HOME=$(BOOT_JDK) \
492491
OMR_DIR=$(OUTPUTDIR)/vm/omr \
493-
SOURCETOOLS_DIR=$(call FixPath,$(OPENJ9_TOPDIR))/sourcetools \
492+
SOURCETOOLS_DIR=$(call MixedPath,$(OPENJ9_TOPDIR))/sourcetools \
494493
SPEC=$(OPENJ9_BUILDSPEC) \
495494
UMA_OPTIONS_EXTRA="-buildDate $(shell date +'%Y%m%d')" \
496495
VERSION_MAJOR=$(VERSION_FEATURE) \

closed/custom/Main.gmk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ JVM_MAIN_TARGETS := j9vm-build
3131
JVM_TOOLS_TARGETS :=
3232
JVM_DOCS_TARGETS :=
3333
JVM_TEST_IMAGE_TARGETS := test-image-openj9
34-
DEFAULT_JMOD_DEPS := j9vm-build
3534
PHASE_MAKEDIRS := $(TOPDIR)/closed/make $(PHASE_MAKEDIRS)
3635

3736
OPENJ9_MAKE := $(MAKE) $(MAKE_ARGS) -f $(TOPDIR)/closed/OpenJ9.gmk

closed/custom/common/MakeBase.gmk

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# ===========================================================================
2+
# (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved
3+
# ===========================================================================
4+
# This code is free software; you can redistribute it and/or modify it
5+
# under the terms of the GNU General Public License version 2 only, as
6+
# published by the Free Software Foundation.
7+
#
8+
# IBM designates this particular file as subject to the "Classpath" exception
9+
# as provided by IBM in the LICENSE file that accompanied this code.
10+
#
11+
# This code is distributed in the hope that it will be useful, but WITHOUT
12+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
# version 2 for more details (a copy is included in the LICENSE file that
15+
# accompanied this code).
16+
#
17+
# You should have received a copy of the GNU General Public License version
18+
# 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
19+
# ===========================================================================
20+
21+
# Echo a command and then execute it.
22+
# $1 - the command
23+
define EchoAndRun
24+
@ $(ECHO) $1
25+
@ $1
26+
endef
27+
28+
# On Windows, FixPath yields backslashes which can cause problems, so
29+
# we use PATHTOOL instead for tools (like java) that support both.
30+
ifeq ($(call isTargetOs, windows), true)
31+
MixedPath = $(shell $(PATHTOOL) -m $1)
32+
else
33+
MixedPath = $1
34+
endif

closed/openjdk-tag.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
OPENJDK_TAG := jdk-17.0.8+6
1+
OPENJDK_TAG := jdk-17.0.8+7

make/conf/version-numbers.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ DEFAULT_VERSION_CLASSFILE_MINOR=0
3939
DEFAULT_VERSION_DOCS_API_SINCE=11
4040
DEFAULT_ACCEPTABLE_BOOT_VERSIONS="16 17"
4141
DEFAULT_JDK_SOURCE_TARGET_VERSION=17
42-
DEFAULT_PROMOTED_VERSION_PRE=ea
42+
DEFAULT_PROMOTED_VERSION_PRE=

src/java.base/share/classes/java/util/jar/JarFile.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
2929
import jdk.internal.access.JavaUtilZipFileAccess;
3030
import sun.security.action.GetPropertyAction;
3131
import sun.security.util.ManifestEntryVerifier;
32+
import sun.security.util.SignatureFileVerifier;
3233

3334
import java.io.ByteArrayInputStream;
3435
import java.io.EOFException;
@@ -151,8 +152,6 @@ public class JarFile extends ZipFile {
151152
private static final boolean MULTI_RELEASE_ENABLED;
152153
private static final boolean MULTI_RELEASE_FORCED;
153154
private static final ThreadLocal<Boolean> isInitializing = new ThreadLocal<>();
154-
// The maximum size of array to allocate. Some VMs reserve some header words in an array.
155-
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
156155

157156
private SoftReference<Manifest> manRef;
158157
private JarEntry manEntry;
@@ -800,8 +799,11 @@ private void initializeVerifier() {
800799
private byte[] getBytes(ZipEntry ze) throws IOException {
801800
try (InputStream is = super.getInputStream(ze)) {
802801
long uncompressedSize = ze.getSize();
803-
if (uncompressedSize > MAX_ARRAY_SIZE) {
804-
throw new IOException("Unsupported size: " + uncompressedSize);
802+
if (uncompressedSize > SignatureFileVerifier.MAX_SIG_FILE_SIZE) {
803+
throw new IOException("Unsupported size: " + uncompressedSize +
804+
" for JarEntry " + ze.getName() +
805+
". Allowed max size: " +
806+
SignatureFileVerifier.MAX_SIG_FILE_SIZE + " bytes");
805807
}
806808
int len = (int)uncompressedSize;
807809
int bytesRead;

src/java.base/share/classes/java/util/zip/ZipFile.java

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import jdk.internal.ref.CleanerFactory;
7070
import jdk.internal.vm.annotation.Stable;
7171
import sun.nio.cs.UTF_8;
72+
import sun.security.action.GetBooleanAction;
7273
import sun.security.util.SignatureFileVerifier;
7374

7475
import static java.util.zip.ZipConstants64.*;
@@ -121,6 +122,12 @@ public class ZipFile implements ZipConstants, Closeable {
121122
*/
122123
public static final int OPEN_DELETE = 0x4;
123124

125+
/**
126+
* Flag which specifies whether the validation of the Zip64 extra
127+
* fields should be disabled
128+
*/
129+
private static final boolean disableZip64ExtraFieldValidation =
130+
GetBooleanAction.privilegedGetProperty("jdk.util.zip.disableZip64ExtraFieldValidation");
124131
/**
125132
* Opens a zip file for reading.
126133
*
@@ -1195,6 +1202,16 @@ private int checkAndAddEntry(int pos, int index)
11951202
if (entryPos + nlen > cen.length - ENDHDR) {
11961203
zerror("invalid CEN header (bad header size)");
11971204
}
1205+
1206+
int elen = CENEXT(cen, pos);
1207+
if (elen > 0 && !disableZip64ExtraFieldValidation) {
1208+
long extraStartingOffset = pos + CENHDR + nlen;
1209+
if ((int)extraStartingOffset != extraStartingOffset) {
1210+
zerror("invalid CEN header (bad extra offset)");
1211+
}
1212+
checkExtraFields(pos, (int)extraStartingOffset, elen);
1213+
}
1214+
11981215
try {
11991216
ZipCoder zcp = zipCoderForPos(pos);
12001217
int hash = zcp.checkedHash(cen, entryPos, nlen);
@@ -1211,6 +1228,119 @@ private int checkAndAddEntry(int pos, int index)
12111228
return nlen;
12121229
}
12131230

1231+
/**
1232+
* Validate the Zip64 Extra block fields
1233+
* @param startingOffset Extra Field starting offset within the CEN
1234+
* @param extraFieldLen Length of this Extra field
1235+
* @throws ZipException If an error occurs validating the Zip64 Extra
1236+
* block
1237+
*/
1238+
private void checkExtraFields(int cenPos, int startingOffset,
1239+
int extraFieldLen) throws ZipException {
1240+
// Extra field Length cannot exceed 65,535 bytes per the PKWare
1241+
// APP.note 4.4.11
1242+
if (extraFieldLen > 0xFFFF) {
1243+
zerror("invalid extra field length");
1244+
}
1245+
// CEN Offset where this Extra field ends
1246+
int extraEndOffset = startingOffset + extraFieldLen;
1247+
if (extraEndOffset > cen.length) {
1248+
zerror("Invalid CEN header (extra data field size too long)");
1249+
}
1250+
int currentOffset = startingOffset;
1251+
while (currentOffset < extraEndOffset) {
1252+
int tag = get16(cen, currentOffset);
1253+
currentOffset += Short.BYTES;
1254+
1255+
int tagBlockSize = get16(cen, currentOffset);
1256+
int tagBlockEndingOffset = currentOffset + tagBlockSize;
1257+
1258+
// The ending offset for this tag block should not go past the
1259+
// offset for the end of the extra field
1260+
if (tagBlockEndingOffset > extraEndOffset) {
1261+
zerror("Invalid CEN header (invalid zip64 extra data field size)");
1262+
}
1263+
currentOffset += Short.BYTES;
1264+
1265+
if (tag == ZIP64_EXTID) {
1266+
// Get the compressed size;
1267+
long csize = CENSIZ(cen, cenPos);
1268+
// Get the uncompressed size;
1269+
long size = CENLEN(cen, cenPos);
1270+
checkZip64ExtraFieldValues(currentOffset, tagBlockSize,
1271+
csize, size);
1272+
}
1273+
currentOffset += tagBlockSize;
1274+
}
1275+
}
1276+
1277+
/**
1278+
* Validate the Zip64 Extended Information Extra Field (0x0001) block
1279+
* size and that the uncompressed size and compressed size field
1280+
* values are not negative.
1281+
* Note: As we do not use the LOC offset or Starting disk number
1282+
* field value we will not validate them
1283+
* @param off the starting offset for the Zip64 field value
1284+
* @param blockSize the size of the Zip64 Extended Extra Field
1285+
* @param csize CEN header compressed size value
1286+
* @param size CEN header uncompressed size value
1287+
* @throws ZipException if an error occurs
1288+
*/
1289+
private void checkZip64ExtraFieldValues(int off, int blockSize, long csize,
1290+
long size)
1291+
throws ZipException {
1292+
byte[] cen = this.cen;
1293+
// Validate the Zip64 Extended Information Extra Field (0x0001)
1294+
// length.
1295+
if (!isZip64ExtBlockSizeValid(blockSize)) {
1296+
zerror("Invalid CEN header (invalid zip64 extra data field size)");
1297+
}
1298+
// Check the uncompressed size is not negative
1299+
// Note we do not need to check blockSize is >= 8 as
1300+
// we know its length is at least 8 from the call to
1301+
// isZip64ExtBlockSizeValid()
1302+
if ((size == ZIP64_MAGICVAL)) {
1303+
if(get64(cen, off) < 0) {
1304+
zerror("Invalid zip64 extra block size value");
1305+
}
1306+
}
1307+
// Check the compressed size is not negative
1308+
if ((csize == ZIP64_MAGICVAL) && (blockSize >= 16)) {
1309+
if (get64(cen, off + 8) < 0) {
1310+
zerror("Invalid zip64 extra block compressed size value");
1311+
}
1312+
}
1313+
}
1314+
1315+
/**
1316+
* Validate the size and contents of a Zip64 extended information field
1317+
* The order of the Zip64 fields is fixed, but the fields MUST
1318+
* only appear if the corresponding LOC or CEN field is set to 0xFFFF:
1319+
* or 0xFFFFFFFF:
1320+
* Uncompressed Size - 8 bytes
1321+
* Compressed Size - 8 bytes
1322+
* LOC Header offset - 8 bytes
1323+
* Disk Start Number - 4 bytes
1324+
* See PKWare APP.Note Section 4.5.3 for more details
1325+
*
1326+
* @param blockSize the Zip64 Extended Information Extra Field size
1327+
* @return true if the extra block size is valid; false otherwise
1328+
*/
1329+
private static boolean isZip64ExtBlockSizeValid(int blockSize) {
1330+
/*
1331+
* As the fields must appear in order, the block size indicates which
1332+
* fields to expect:
1333+
* 8 - uncompressed size
1334+
* 16 - uncompressed size, compressed size
1335+
* 24 - uncompressed size, compressed sise, LOC Header offset
1336+
* 28 - uncompressed size, compressed sise, LOC Header offset,
1337+
* and Disk start number
1338+
*/
1339+
return switch(blockSize) {
1340+
case 8, 16, 24, 28 -> true;
1341+
default -> false;
1342+
};
1343+
}
12141344
private int getEntryHash(int index) { return entries[index]; }
12151345
private int getEntryNext(int index) { return entries[index + 1]; }
12161346
private int getEntryPos(int index) { return entries[index + 2]; }

src/java.base/share/classes/sun/security/util/SignatureFileVerifier.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -52,6 +52,7 @@
5252
import java.util.jar.JarFile;
5353
import java.util.jar.Manifest;
5454

55+
import sun.security.action.GetIntegerAction;
5556
import sun.security.jca.Providers;
5657
import sun.security.pkcs.PKCS7;
5758
import sun.security.pkcs.SignerInfo;
@@ -97,6 +98,12 @@ public class SignatureFileVerifier {
9798
/** ConstraintsParameters for checking disabled algorithms */
9899
private JarConstraintsParameters params;
99100

101+
// the maximum allowed size in bytes for the signature-related files
102+
public static final int MAX_SIG_FILE_SIZE = initializeMaxSigFileSize();
103+
104+
// The maximum size of array to allocate. Some VMs reserve some header words in an array.
105+
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
106+
100107
/**
101108
* Create the named SignatureFileVerifier.
102109
*
@@ -842,4 +849,24 @@ void updateSigners(CodeSigner[] newSigners,
842849
signerCache.add(cachedSigners);
843850
signers.put(name, cachedSigners);
844851
}
852+
853+
private static int initializeMaxSigFileSize() {
854+
/*
855+
* System property "jdk.jar.maxSignatureFileSize" used to configure
856+
* the maximum allowed number of bytes for the signature-related files
857+
* in a JAR file.
858+
*/
859+
Integer tmp = GetIntegerAction.privilegedGetProperty(
860+
"jdk.jar.maxSignatureFileSize", 8000000);
861+
if (tmp < 0 || tmp > MAX_ARRAY_SIZE) {
862+
if (debug != null) {
863+
debug.println("Default signature file size 8000000 bytes " +
864+
"is used as the specified size for the " +
865+
"jdk.jar.maxSignatureFileSize system property " +
866+
"is out of range: " + tmp);
867+
}
868+
tmp = 8000000;
869+
}
870+
return tmp;
871+
}
845872
}

0 commit comments

Comments
 (0)