Skip to content

Commit c207d55

Browse files
committed
Merge master jdk-17.0.15+6 into openj9-staging
Signed-off-by: J9 Build <[email protected]>
2 parents 6ae95a7 + b85ca1c commit c207d55

File tree

17 files changed

+609
-226
lines changed

17 files changed

+609
-226
lines changed

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/com/sun/crypto/provider/RSACipher.java

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ private byte[] doFinal() throws BadPaddingException,
385385
byte[] decryptBuffer = RSACore.convert(buffer, 0, bufOfs);
386386
paddingCopy = RSACore.rsa(decryptBuffer, privateKey, false);
387387
result = padding.unpad(paddingCopy);
388-
if (result == null && !forTlsPremasterSecret) {
388+
if (!forTlsPremasterSecret && result == null) {
389389
throw new BadPaddingException
390390
("Padding error in decryption");
391391
}
@@ -405,6 +405,34 @@ private byte[] doFinal() throws BadPaddingException,
405405
}
406406
}
407407

408+
// TLS master secret decode version of the doFinal() method.
409+
private byte[] doFinalForTls(int clientVersion, int serverVersion)
410+
throws BadPaddingException, IllegalBlockSizeException {
411+
if (bufOfs > buffer.length) {
412+
throw new IllegalBlockSizeException("Data must not be longer "
413+
+ "than " + buffer.length + " bytes");
414+
}
415+
byte[] paddingCopy = null;
416+
byte[] result = null;
417+
try {
418+
byte[] decryptBuffer = RSACore.convert(buffer, 0, bufOfs);
419+
420+
paddingCopy = RSACore.rsa(decryptBuffer, privateKey, false);
421+
result = padding.unpadForTls(paddingCopy, clientVersion,
422+
serverVersion);
423+
424+
return result;
425+
} finally {
426+
Arrays.fill(buffer, 0, bufOfs, (byte)0);
427+
bufOfs = 0;
428+
if (paddingCopy != null
429+
&& paddingCopy != buffer // already cleaned
430+
&& paddingCopy != result) { // DO NOT CLEAN, THIS IS RESULT
431+
Arrays.fill(paddingCopy, (byte)0);
432+
}
433+
}
434+
}
435+
408436
// see JCE spec
409437
protected byte[] engineUpdate(byte[] in, int inOfs, int inLen) {
410438
update(in, inOfs, inLen);
@@ -477,38 +505,34 @@ protected Key engineUnwrap(byte[] wrappedKey, String algorithm,
477505
byte[] encoded = null;
478506

479507
update(wrappedKey, 0, wrappedKey.length);
480-
try {
481-
encoded = doFinal();
482-
} catch (BadPaddingException | IllegalBlockSizeException e) {
483-
// BadPaddingException cannot happen for TLS RSA unwrap.
484-
// In that case, padding error is indicated by returning null.
485-
// IllegalBlockSizeException cannot happen in any case,
486-
// because of the length check above.
487-
throw new InvalidKeyException("Unwrapping failed", e);
488-
}
489-
490508
try {
491509
if (isTlsRsaPremasterSecret) {
492510
if (!forTlsPremasterSecret) {
493511
throw new IllegalStateException(
494512
"No TlsRsaPremasterSecretParameterSpec specified");
495513
}
496-
497-
// polish the TLS premaster secret
498-
encoded = KeyUtil.checkTlsPreMasterSecretKey(
499-
((TlsRsaPremasterSecretParameterSpec) spec).getClientVersion(),
500-
((TlsRsaPremasterSecretParameterSpec) spec).getServerVersion(),
501-
random, encoded, encoded == null);
514+
TlsRsaPremasterSecretParameterSpec parameterSpec =
515+
(TlsRsaPremasterSecretParameterSpec) spec;
516+
encoded = doFinalForTls(parameterSpec.getClientVersion(),
517+
parameterSpec.getServerVersion());
518+
} else {
519+
encoded = doFinal();
502520
}
503-
504521
return ConstructKeys.constructKey(encoded, algorithm, type);
522+
523+
} catch (BadPaddingException | IllegalBlockSizeException e) {
524+
// BadPaddingException cannot happen for TLS RSA unwrap.
525+
// Neither padding error nor server version error is indicated
526+
// for TLS, but a fake unwrapped value is returned.
527+
// IllegalBlockSizeException cannot happen in any case,
528+
// because of the length check above.
529+
throw new InvalidKeyException("Unwrapping failed", e);
505530
} finally {
506531
if (encoded != null) {
507532
Arrays.fill(encoded, (byte) 0);
508533
}
509534
}
510535
}
511-
512536
// see JCE spec
513537
protected int engineGetKeySize(Key key) throws InvalidKeyException {
514538
RSAKey rsaKey = RSAKeyFactory.toRSAKey(key);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ private Manifest getManifestFromReference() throws IOException {
422422
jv = new JarVerifier(manEntry.getName(), b);
423423
} else {
424424
if (JarVerifier.debug != null) {
425-
JarVerifier.debug.println("Multiple MANIFEST.MF found. Treat JAR file as unsigned");
425+
JarVerifier.debug.println(
426+
JarVerifier.MULTIPLE_MANIFEST_WARNING);
426427
}
427428
}
428429
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,17 @@ private JarEntry checkManifest(JarEntry e)
9797
jv = new JarVerifier(e.getName(), bytes);
9898
mev = new ManifestEntryVerifier(man, jv.manifestName);
9999
}
100-
return (JarEntry)super.getNextEntry();
100+
JarEntry nextEntry = (JarEntry)super.getNextEntry();
101+
if (nextEntry != null &&
102+
JarFile.MANIFEST_NAME.equalsIgnoreCase(nextEntry.getName())) {
103+
if (JarVerifier.debug != null) {
104+
JarVerifier.debug.println(JarVerifier.MULTIPLE_MANIFEST_WARNING);
105+
}
106+
107+
jv = null;
108+
mev = null;
109+
}
110+
return nextEntry;
101111
}
102112
return e;
103113
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, 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
@@ -44,6 +44,9 @@
4444
*/
4545
class JarVerifier {
4646

47+
public static final String MULTIPLE_MANIFEST_WARNING =
48+
"WARNING: Multiple MANIFEST.MF found. Treat JAR file as unsigned.";
49+
4750
/* Are we debugging ? */
4851
static final Debug debug = Debug.getInstance("jar");
4952

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@
4040
* @since 1.1
4141
*/
4242
public class DeflaterOutputStream extends FilterOutputStream {
43+
44+
/*
45+
* The default size of the output buffer
46+
*/
47+
static final int DEFAULT_BUF_SIZE = 512;
48+
49+
/*
50+
* When calling Deflater.deflate() with Deflater.SYNC_FLUSH or Deflater.FULL_FLUSH,
51+
* the callers are expected to ensure that the size of the buffer is greater than 6.
52+
* This expectation comes from the underlying zlib library which in its zlib.h
53+
* states:
54+
* "If deflate returns with avail_out == 0, this function must be called again
55+
* with the same value of the flush parameter and more output space (updated
56+
* avail_out), until the flush is complete (deflate returns with non-zero
57+
* avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
58+
* avail_out is greater than six when the flush marker begins, in order to avoid
59+
* repeated flush markers upon calling deflate() again when avail_out == 0."
60+
*/
61+
private static final int SYNC_FLUSH_MIN_BUF_SIZE = 7;
62+
4363
/**
4464
* Compressor for this stream.
4565
*/
@@ -123,7 +143,7 @@ public DeflaterOutputStream(OutputStream out, Deflater def, int size) {
123143
public DeflaterOutputStream(OutputStream out,
124144
Deflater def,
125145
boolean syncFlush) {
126-
this(out, def, 512, syncFlush);
146+
this(out, def, DEFAULT_BUF_SIZE, syncFlush);
127147
}
128148

129149

@@ -138,7 +158,7 @@ public DeflaterOutputStream(OutputStream out,
138158
* @param def the compressor ("deflater")
139159
*/
140160
public DeflaterOutputStream(OutputStream out, Deflater def) {
141-
this(out, def, 512, false);
161+
this(out, def, DEFAULT_BUF_SIZE, false);
142162
}
143163

144164
boolean usesDefaultDeflater = false;
@@ -158,7 +178,7 @@ public DeflaterOutputStream(OutputStream out, Deflater def) {
158178
* @since 1.7
159179
*/
160180
public DeflaterOutputStream(OutputStream out, boolean syncFlush) {
161-
this(out, out != null ? new Deflater() : null, 512, syncFlush);
181+
this(out, out != null ? new Deflater() : null, DEFAULT_BUF_SIZE, syncFlush);
162182
usesDefaultDeflater = true;
163183
}
164184

@@ -181,6 +201,7 @@ public DeflaterOutputStream(OutputStream out) {
181201
* @param b the byte to be written
182202
* @throws IOException if an I/O error has occurred
183203
*/
204+
@Override
184205
public void write(int b) throws IOException {
185206
byte[] buf = new byte[1];
186207
buf[0] = (byte)(b & 0xff);
@@ -195,6 +216,7 @@ public void write(int b) throws IOException {
195216
* @param len the length of the data
196217
* @throws IOException if an I/O error has occurred
197218
*/
219+
@Override
198220
public void write(byte[] b, int off, int len) throws IOException {
199221
if (def.finished()) {
200222
throw new IOException("write beyond end of stream");
@@ -238,6 +260,7 @@ public void finish() throws IOException {
238260
* underlying stream.
239261
* @throws IOException if an I/O error has occurred
240262
*/
263+
@Override
241264
public void close() throws IOException {
242265
if (!closed) {
243266
try {
@@ -277,13 +300,20 @@ protected void deflate() throws IOException {
277300
*
278301
* @since 1.7
279302
*/
303+
@Override
280304
public void flush() throws IOException {
281305
if (syncFlush && !def.finished()) {
282306
int len = 0;
283-
while ((len = def.deflate(buf, 0, buf.length, Deflater.SYNC_FLUSH)) > 0)
284-
{
285-
out.write(buf, 0, len);
286-
if (len < buf.length)
307+
// For SYNC_FLUSH, the Deflater.deflate() expects the callers
308+
// to use a buffer whose length is greater than 6 to avoid
309+
// flush marker (5 bytes) being repeatedly output to the output buffer
310+
// every time it is invoked.
311+
final byte[] flushBuf = buf.length < SYNC_FLUSH_MIN_BUF_SIZE
312+
? new byte[DEFAULT_BUF_SIZE]
313+
: buf;
314+
while ((len = def.deflate(flushBuf, 0, flushBuf.length, Deflater.SYNC_FLUSH)) > 0) {
315+
out.write(flushBuf, 0, len);
316+
if (len < flushBuf.length)
287317
break;
288318
}
289319
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public GZIPOutputStream(OutputStream out, int size, boolean syncFlush)
109109
* @throws IOException If an I/O error has occurred.
110110
*/
111111
public GZIPOutputStream(OutputStream out) throws IOException {
112-
this(out, 512, false);
112+
this(out, DeflaterOutputStream.DEFAULT_BUF_SIZE, false);
113113
}
114114

115115
/**
@@ -131,7 +131,7 @@ public GZIPOutputStream(OutputStream out) throws IOException {
131131
public GZIPOutputStream(OutputStream out, boolean syncFlush)
132132
throws IOException
133133
{
134-
this(out, 512, syncFlush);
134+
this(out, DeflaterOutputStream.DEFAULT_BUF_SIZE, syncFlush);
135135
}
136136

137137
/**

0 commit comments

Comments
 (0)