Skip to content

Commit 524170d

Browse files
committed
Merge
2 parents ed62438 + 856bab3 commit 524170d

File tree

12 files changed

+279
-78
lines changed

12 files changed

+279
-78
lines changed

make/autoconf/version-numbers

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DEFAULT_VERSION_DATE=2025-07-15
3737
DEFAULT_VERSION_CLASSFILE_MAJOR=55 # "`$EXPR $DEFAULT_VERSION_FEATURE + 44`"
3838
DEFAULT_VERSION_CLASSFILE_MINOR=0
3939
DEFAULT_ACCEPTABLE_BOOT_VERSIONS="10 11"
40-
DEFAULT_PROMOTED_VERSION_PRE=ea
40+
DEFAULT_PROMOTED_VERSION_PRE=
4141

4242
LAUNCHER_NAME=openjdk
4343
PRODUCT_NAME=OpenJDK

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, 2012, 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
@@ -941,6 +941,14 @@ static bool can_overflow(const TypeInt* t, jint c) {
941941
(c > 0 && (java_add(t_hi, c) < t_hi)));
942942
}
943943

944+
// Check if addition of a long with type 't' and a constant 'c' can overflow.
945+
static bool can_overflow(const TypeLong* t, jlong c) {
946+
jlong t_lo = t->_lo;
947+
jlong t_hi = t->_hi;
948+
return ((c < 0 && (java_add(t_lo, c) > t_lo)) ||
949+
(c > 0 && (java_add(t_hi, c) < t_hi)));
950+
}
951+
944952
//=============================================================================
945953
//------------------------------Idealize---------------------------------------
946954
// MINs show up in range-check loop limit calculations. Look for
@@ -1062,6 +1070,31 @@ const Type *MinINode::add_ring( const Type *t0, const Type *t1 ) const {
10621070
//
10631071
// Note: we assume that SubL was already replaced by an AddL, and that the stride
10641072
// has its sign flipped: SubL(limit, stride) -> AddL(limit, -stride).
1073+
//
1074+
// Proof MaxL collapsed version equivalent to original (MinL version similar):
1075+
// is_sub_con ensures that con1, con2 ∈ [min_int, 0[
1076+
//
1077+
// Original:
1078+
// - AddL2 underflow => x + con2 ∈ ]max_long - min_int, max_long], ALWAYS BAILOUT as x + con1 + con2 surely fails can_overflow (*)
1079+
// - AddL2 no underflow => x + con2 ∈ [min_long, max_long]
1080+
// - MaxL2 clamp => min_int
1081+
// - AddL1 underflow: NOT POSSIBLE: cannot underflow since min_int + con1 ∈ [2 * min_int, min_int] always > min_long
1082+
// - AddL1 no underflow => min_int + con1 ∈ [2 * min_int, min_int]
1083+
// - MaxL1 clamp => min_int (RESULT 1)
1084+
// - MaxL1 no clamp: NOT POSSIBLE: min_int + con1 ∈ [2 * min_int, min_int] always <= min_int, so clamp always taken
1085+
// - MaxL2 no clamp => x + con2 ∈ [min_int, max_long]
1086+
// - AddL1 underflow: NOT POSSIBLE: cannot underflow since x + con2 + con1 ∈ [2 * min_int, max_long] always > min_long
1087+
// - AddL1 no underflow => x + con2 + con1 ∈ [2 * min_int, max_long]
1088+
// - MaxL1 clamp => min_int (RESULT 2)
1089+
// - MaxL1 no clamp => x + con2 + con1 ∈ ]min_int, max_long] (RESULT 3)
1090+
//
1091+
// Collapsed:
1092+
// - AddL2 (cannot underflow) => con2 + con1 ∈ [2 * min_int, 0]
1093+
// - AddL1 underflow: NOT POSSIBLE: would have bailed out at can_overflow (*)
1094+
// - AddL1 no underflow => x + con2 + con1 ∈ [min_long, max_long]
1095+
// - MaxL clamp => min_int (RESULT 1 and RESULT 2)
1096+
// - MaxL no clamp => x + con2 + con1 ∈ ]min_int, max_long] (RESULT 3)
1097+
//
10651098
static bool is_clamp(PhaseGVN* phase, Node* n, Node* c) {
10661099
// Check that the two clamps have the correct values.
10671100
jlong clamp = (n->Opcode() == Op_MaxL) ? min_jint : max_jint;
@@ -1093,6 +1126,10 @@ Node* fold_subI_no_underflow_pattern(Node* n, PhaseGVN* phase) {
10931126
Node* x = add2->in(1);
10941127
Node* con2 = add2->in(2);
10951128
if (is_sub_con(phase, n, con2)) {
1129+
// Collapsed graph not equivalent if potential over/underflow -> bailing out (*)
1130+
if (can_overflow(phase->type(x)->is_long(), con1->get_long() + con2->get_long())) {
1131+
return NULL;
1132+
}
10961133
Node* new_con = phase->transform(new AddLNode(con1, con2));
10971134
Node* new_sub = phase->transform(new AddLNode(x, new_con));
10981135
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
@@ -384,7 +384,7 @@ private byte[] doFinal() throws BadPaddingException,
384384
byte[] decryptBuffer = RSACore.convert(buffer, 0, bufOfs);
385385
paddingCopy = RSACore.rsa(decryptBuffer, privateKey, false);
386386
result = padding.unpad(paddingCopy);
387-
if (result == null && !forTlsPremasterSecret) {
387+
if (!forTlsPremasterSecret && result == null) {
388388
throw new BadPaddingException
389389
("Padding error in decryption");
390390
}
@@ -404,6 +404,34 @@ private byte[] doFinal() throws BadPaddingException,
404404
}
405405
}
406406

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

478506
update(wrappedKey, 0, wrappedKey.length);
479-
try {
480-
encoded = doFinal();
481-
} catch (BadPaddingException | IllegalBlockSizeException e) {
482-
// BadPaddingException cannot happen for TLS RSA unwrap.
483-
// In that case, padding error is indicated by returning null.
484-
// IllegalBlockSizeException cannot happen in any case,
485-
// because of the length check above.
486-
throw new InvalidKeyException("Unwrapping failed", e);
487-
}
488-
489507
try {
490508
if (isTlsRsaPremasterSecret) {
491509
if (!forTlsPremasterSecret) {
492510
throw new IllegalStateException(
493511
"No TlsRsaPremasterSecretParameterSpec specified");
494512
}
495-
496-
// polish the TLS premaster secret
497-
encoded = KeyUtil.checkTlsPreMasterSecretKey(
498-
((TlsRsaPremasterSecretParameterSpec) spec).getClientVersion(),
499-
((TlsRsaPremasterSecretParameterSpec) spec).getServerVersion(),
500-
random, encoded, encoded == null);
513+
TlsRsaPremasterSecretParameterSpec parameterSpec =
514+
(TlsRsaPremasterSecretParameterSpec) spec;
515+
encoded = doFinalForTls(parameterSpec.getClientVersion(),
516+
parameterSpec.getServerVersion());
517+
} else {
518+
encoded = doFinal();
501519
}
502-
503520
return ConstructKeys.constructKey(encoded, algorithm, type);
521+
522+
} catch (BadPaddingException | IllegalBlockSizeException e) {
523+
// BadPaddingException cannot happen for TLS RSA unwrap.
524+
// Neither padding error nor server version error is indicated
525+
// for TLS, but a fake unwrapped value is returned.
526+
// IllegalBlockSizeException cannot happen in any case,
527+
// because of the length check above.
528+
throw new InvalidKeyException("Unwrapping failed", e);
504529
} finally {
505530
if (encoded != null) {
506531
Arrays.fill(encoded, (byte) 0);
507532
}
508533
}
509534
}
510-
511535
// see JCE spec
512536
protected int engineGetKeySize(Key key) throws InvalidKeyException {
513537
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
@@ -424,7 +424,8 @@ private Manifest getManifestFromReference() throws IOException {
424424
jv = new JarVerifier(manEntry.getName(), b);
425425
} else {
426426
if (JarVerifier.debug != null) {
427-
JarVerifier.debug.println("Multiple MANIFEST.MF found. Treat JAR file as unsigned");
427+
JarVerifier.debug.println(
428+
JarVerifier.MULTIPLE_MANIFEST_WARNING);
428429
}
429430
}
430431
}

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

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

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
@@ -41,6 +41,26 @@
4141
*/
4242
public
4343
class DeflaterOutputStream extends FilterOutputStream {
44+
45+
/*
46+
* The default size of the output buffer
47+
*/
48+
static final int DEFAULT_BUF_SIZE = 512;
49+
50+
/*
51+
* When calling Deflater.deflate() with Deflater.SYNC_FLUSH or Deflater.FULL_FLUSH,
52+
* the callers are expected to ensure that the size of the buffer is greater than 6.
53+
* This expectation comes from the underlying zlib library which in its zlib.h
54+
* states:
55+
* "If deflate returns with avail_out == 0, this function must be called again
56+
* with the same value of the flush parameter and more output space (updated
57+
* avail_out), until the flush is complete (deflate returns with non-zero
58+
* avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
59+
* avail_out is greater than six when the flush marker begins, in order to avoid
60+
* repeated flush markers upon calling deflate() again when avail_out == 0."
61+
*/
62+
private static final int SYNC_FLUSH_MIN_BUF_SIZE = 7;
63+
4464
/**
4565
* Compressor for this stream.
4666
*/
@@ -124,7 +144,7 @@ public DeflaterOutputStream(OutputStream out, Deflater def, int size) {
124144
public DeflaterOutputStream(OutputStream out,
125145
Deflater def,
126146
boolean syncFlush) {
127-
this(out, def, 512, syncFlush);
147+
this(out, def, DEFAULT_BUF_SIZE, syncFlush);
128148
}
129149

130150

@@ -139,7 +159,7 @@ public DeflaterOutputStream(OutputStream out,
139159
* @param def the compressor ("deflater")
140160
*/
141161
public DeflaterOutputStream(OutputStream out, Deflater def) {
142-
this(out, def, 512, false);
162+
this(out, def, DEFAULT_BUF_SIZE, false);
143163
}
144164

145165
boolean usesDefaultDeflater = false;
@@ -159,7 +179,7 @@ public DeflaterOutputStream(OutputStream out, Deflater def) {
159179
* @since 1.7
160180
*/
161181
public DeflaterOutputStream(OutputStream out, boolean syncFlush) {
162-
this(out, new Deflater(), 512, syncFlush);
182+
this(out, new Deflater(), DEFAULT_BUF_SIZE, syncFlush);
163183
usesDefaultDeflater = true;
164184
}
165185

@@ -182,6 +202,7 @@ public DeflaterOutputStream(OutputStream out) {
182202
* @param b the byte to be written
183203
* @exception IOException if an I/O error has occurred
184204
*/
205+
@Override
185206
public void write(int b) throws IOException {
186207
byte[] buf = new byte[1];
187208
buf[0] = (byte)(b & 0xff);
@@ -196,6 +217,7 @@ public void write(int b) throws IOException {
196217
* @param len the length of the data
197218
* @exception IOException if an I/O error has occurred
198219
*/
220+
@Override
199221
public void write(byte[] b, int off, int len) throws IOException {
200222
if (def.finished()) {
201223
throw new IOException("write beyond end of stream");
@@ -239,6 +261,7 @@ public void finish() throws IOException {
239261
* underlying stream.
240262
* @exception IOException if an I/O error has occurred
241263
*/
264+
@Override
242265
public void close() throws IOException {
243266
if (!closed) {
244267
try {
@@ -278,13 +301,20 @@ protected void deflate() throws IOException {
278301
*
279302
* @since 1.7
280303
*/
304+
@Override
281305
public void flush() throws IOException {
282306
if (syncFlush && !def.finished()) {
283307
int len = 0;
284-
while ((len = def.deflate(buf, 0, buf.length, Deflater.SYNC_FLUSH)) > 0)
285-
{
286-
out.write(buf, 0, len);
287-
if (len < buf.length)
308+
// For SYNC_FLUSH, the Deflater.deflate() expects the callers
309+
// to use a buffer whose length is greater than 6 to avoid
310+
// flush marker (5 bytes) being repeatedly output to the output buffer
311+
// every time it is invoked.
312+
final byte[] flushBuf = buf.length < SYNC_FLUSH_MIN_BUF_SIZE
313+
? new byte[DEFAULT_BUF_SIZE]
314+
: buf;
315+
while ((len = def.deflate(flushBuf, 0, flushBuf.length, Deflater.SYNC_FLUSH)) > 0) {
316+
out.write(flushBuf, 0, len);
317+
if (len < flushBuf.length)
288318
break;
289319
}
290320
}

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

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

113113
/**
@@ -129,7 +129,7 @@ public GZIPOutputStream(OutputStream out) throws IOException {
129129
public GZIPOutputStream(OutputStream out, boolean syncFlush)
130130
throws IOException
131131
{
132-
this(out, 512, syncFlush);
132+
this(out, DeflaterOutputStream.DEFAULT_BUF_SIZE, syncFlush);
133133
}
134134

135135
/**

0 commit comments

Comments
 (0)