Skip to content

Commit b649468

Browse files
author
Datadog Syncup Service
committed
Merge branch 'upstream-master'
2 parents bc44f69 + 85d0ab5 commit b649468

File tree

53 files changed

+3322
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3322
-538
lines changed

src/hotspot/share/c1/c1_globals.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 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
@@ -287,9 +287,11 @@
287287
develop(bool, InstallMethods, true, \
288288
"Install methods at the end of successful compilations") \
289289
\
290+
/* The compiler assumes, in many places, that methods are at most 1MB. */ \
291+
/* Therefore, we restrict this flag to at most 1MB. */ \
290292
develop(intx, NMethodSizeLimit, (64*K)*wordSize, \
291293
"Maximum size of a compiled method.") \
292-
range(0, max_jint) \
294+
range(0, 1*M) \
293295
\
294296
develop(bool, TraceFPUStack, false, \
295297
"Trace emulation of the FPU stack (intel only)") \

src/hotspot/share/opto/addnode.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, 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
@@ -1164,6 +1164,14 @@ static bool can_overflow(const TypeInt* t, jint c) {
11641164
(c > 0 && (java_add(t_hi, c) < t_hi)));
11651165
}
11661166

1167+
// Check if addition of a long with type 't' and a constant 'c' can overflow.
1168+
static bool can_overflow(const TypeLong* t, jlong c) {
1169+
jlong t_lo = t->_lo;
1170+
jlong t_hi = t->_hi;
1171+
return ((c < 0 && (java_add(t_lo, c) > t_lo)) ||
1172+
(c > 0 && (java_add(t_hi, c) < t_hi)));
1173+
}
1174+
11671175
//=============================================================================
11681176
//------------------------------Idealize---------------------------------------
11691177
// MINs show up in range-check loop limit calculations. Look for
@@ -1285,6 +1293,31 @@ const Type *MinINode::add_ring( const Type *t0, const Type *t1 ) const {
12851293
//
12861294
// Note: we assume that SubL was already replaced by an AddL, and that the stride
12871295
// has its sign flipped: SubL(limit, stride) -> AddL(limit, -stride).
1296+
//
1297+
// Proof MaxL collapsed version equivalent to original (MinL version similar):
1298+
// is_sub_con ensures that con1, con2 ∈ [min_int, 0[
1299+
//
1300+
// Original:
1301+
// - AddL2 underflow => x + con2 ∈ ]max_long - min_int, max_long], ALWAYS BAILOUT as x + con1 + con2 surely fails can_overflow (*)
1302+
// - AddL2 no underflow => x + con2 ∈ [min_long, max_long]
1303+
// - MaxL2 clamp => min_int
1304+
// - AddL1 underflow: NOT POSSIBLE: cannot underflow since min_int + con1 ∈ [2 * min_int, min_int] always > min_long
1305+
// - AddL1 no underflow => min_int + con1 ∈ [2 * min_int, min_int]
1306+
// - MaxL1 clamp => min_int (RESULT 1)
1307+
// - MaxL1 no clamp: NOT POSSIBLE: min_int + con1 ∈ [2 * min_int, min_int] always <= min_int, so clamp always taken
1308+
// - MaxL2 no clamp => x + con2 ∈ [min_int, max_long]
1309+
// - AddL1 underflow: NOT POSSIBLE: cannot underflow since x + con2 + con1 ∈ [2 * min_int, max_long] always > min_long
1310+
// - AddL1 no underflow => x + con2 + con1 ∈ [2 * min_int, max_long]
1311+
// - MaxL1 clamp => min_int (RESULT 2)
1312+
// - MaxL1 no clamp => x + con2 + con1 ∈ ]min_int, max_long] (RESULT 3)
1313+
//
1314+
// Collapsed:
1315+
// - AddL2 (cannot underflow) => con2 + con1 ∈ [2 * min_int, 0]
1316+
// - AddL1 underflow: NOT POSSIBLE: would have bailed out at can_overflow (*)
1317+
// - AddL1 no underflow => x + con2 + con1 ∈ [min_long, max_long]
1318+
// - MaxL clamp => min_int (RESULT 1 and RESULT 2)
1319+
// - MaxL no clamp => x + con2 + con1 ∈ ]min_int, max_long] (RESULT 3)
1320+
//
12881321
Node* fold_subI_no_underflow_pattern(Node* n, PhaseGVN* phase) {
12891322
assert(n->Opcode() == Op_MaxL || n->Opcode() == Op_MinL, "sanity");
12901323
// Check that the two clamps have the correct values.
@@ -1314,6 +1347,10 @@ Node* fold_subI_no_underflow_pattern(Node* n, PhaseGVN* phase) {
13141347
Node* x = add2->in(1);
13151348
Node* con2 = add2->in(2);
13161349
if (is_sub_con(con2)) {
1350+
// Collapsed graph not equivalent if potential over/underflow -> bailing out (*)
1351+
if (can_overflow(phase->type(x)->is_long(), con1->get_long() + con2->get_long())) {
1352+
return nullptr;
1353+
}
13171354
Node* new_con = phase->transform(new AddLNode(con1, con2));
13181355
Node* new_sub = phase->transform(new AddLNode(x, new_con));
13191356
n->set_req_X(1, new_sub, phase);

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)