Skip to content

Commit 2b55794

Browse files
committed
Merge
2 parents 5b97474 + 35c254f commit 2b55794

File tree

13 files changed

+280
-79
lines changed

13 files changed

+280
-79
lines changed

hotspot/src/share/vm/opto/addnode.cpp

+38-1
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
@@ -1052,6 +1060,31 @@ Node *MinINode::Ideal(PhaseGVN *phase, bool can_reshape) {
10521060
//
10531061
// Note: we assume that SubL was already replaced by an AddL, and that the stride
10541062
// has its sign flipped: SubL(limit, stride) -> AddL(limit, -stride).
1063+
//
1064+
// Proof MaxL collapsed version equivalent to original (MinL version similar):
1065+
// is_sub_con ensures that con1, con2 ∈ [min_int, 0[
1066+
//
1067+
// Original:
1068+
// - AddL2 underflow => x + con2 ∈ ]max_long - min_int, max_long], ALWAYS BAILOUT as x + con1 + con2 surely fails can_overflow (*)
1069+
// - AddL2 no underflow => x + con2 ∈ [min_long, max_long]
1070+
// - MaxL2 clamp => min_int
1071+
// - AddL1 underflow: NOT POSSIBLE: cannot underflow since min_int + con1 ∈ [2 * min_int, min_int] always > min_long
1072+
// - AddL1 no underflow => min_int + con1 ∈ [2 * min_int, min_int]
1073+
// - MaxL1 clamp => min_int (RESULT 1)
1074+
// - MaxL1 no clamp: NOT POSSIBLE: min_int + con1 ∈ [2 * min_int, min_int] always <= min_int, so clamp always taken
1075+
// - MaxL2 no clamp => x + con2 ∈ [min_int, max_long]
1076+
// - AddL1 underflow: NOT POSSIBLE: cannot underflow since x + con2 + con1 ∈ [2 * min_int, max_long] always > min_long
1077+
// - AddL1 no underflow => x + con2 + con1 ∈ [2 * min_int, max_long]
1078+
// - MaxL1 clamp => min_int (RESULT 2)
1079+
// - MaxL1 no clamp => x + con2 + con1 ∈ ]min_int, max_long] (RESULT 3)
1080+
//
1081+
// Collapsed:
1082+
// - AddL2 (cannot underflow) => con2 + con1 ∈ [2 * min_int, 0]
1083+
// - AddL1 underflow: NOT POSSIBLE: would have bailed out at can_overflow (*)
1084+
// - AddL1 no underflow => x + con2 + con1 ∈ [min_long, max_long]
1085+
// - MaxL clamp => min_int (RESULT 1 and RESULT 2)
1086+
// - MaxL no clamp => x + con2 + con1 ∈ ]min_int, max_long] (RESULT 3)
1087+
//
10551088
static bool is_clamp(PhaseGVN* phase, Node* n, Node* c) {
10561089
// Check that the two clamps have the correct values.
10571090
jlong clamp = (n->Opcode() == Op_MaxL) ? min_jint : max_jint;
@@ -1083,6 +1116,10 @@ Node* fold_subI_no_underflow_pattern(Node* n, PhaseGVN* phase) {
10831116
Node* x = add2->in(1);
10841117
Node* con2 = add2->in(2);
10851118
if (is_sub_con(phase, n, con2)) {
1119+
// Collapsed graph not equivalent if potential over/underflow -> bailing out (*)
1120+
if (can_overflow(phase->type(x)->is_long(), con1->get_long() + con2->get_long())) {
1121+
return NULL;
1122+
}
10861123
Node* new_con = phase->transform(new (phase->C) AddLNode(con1, con2));
10871124
Node* new_sub = phase->transform(new (phase->C) AddLNode(x, new_con));
10881125
n->set_req_X(1, new_sub, phase);

jdk/make/data/tzdata/zone.tab

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ PF -0900-13930 Pacific/Marquesas Marquesas Islands
333333
PF -2308-13457 Pacific/Gambier Gambier Islands
334334
PG -0930+14710 Pacific/Port_Moresby most of Papua New Guinea
335335
PG -0613+15534 Pacific/Bougainville Bougainville
336-
PH +1435+12100 Asia/Manila
336+
PH +143512+1205804 Asia/Manila
337337
PK +2452+06703 Asia/Karachi
338338
PL +5215+02100 Europe/Warsaw
339339
PM +4703-05620 America/Miquelon

jdk/src/share/classes/com/sun/crypto/provider/RSACipher.java

+43-19
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ private byte[] doFinal() throws BadPaddingException,
383383
byte[] decryptBuffer = RSACore.convert(buffer, 0, bufOfs);
384384
paddingCopy = RSACore.rsa(decryptBuffer, privateKey, false);
385385
result = padding.unpad(paddingCopy);
386-
if (result == null && !forTlsPremasterSecret) {
386+
if (!forTlsPremasterSecret && result == null) {
387387
throw new BadPaddingException
388388
("Padding error in decryption");
389389
}
@@ -403,6 +403,34 @@ private byte[] doFinal() throws BadPaddingException,
403403
}
404404
}
405405

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

476504
update(wrappedKey, 0, wrappedKey.length);
477-
try {
478-
encoded = doFinal();
479-
} catch (BadPaddingException | IllegalBlockSizeException e) {
480-
// BadPaddingException cannot happen for TLS RSA unwrap.
481-
// In that case, padding error is indicated by returning null.
482-
// IllegalBlockSizeException cannot happen in any case,
483-
// because of the length check above.
484-
throw new InvalidKeyException("Unwrapping failed", e);
485-
}
486-
487505
try {
488506
if (isTlsRsaPremasterSecret) {
489507
if (!forTlsPremasterSecret) {
490508
throw new IllegalStateException(
491509
"No TlsRsaPremasterSecretParameterSpec specified");
492510
}
493-
494-
// polish the TLS premaster secret
495-
encoded = KeyUtil.checkTlsPreMasterSecretKey(
496-
((TlsRsaPremasterSecretParameterSpec) spec).getClientVersion(),
497-
((TlsRsaPremasterSecretParameterSpec) spec).getServerVersion(),
498-
random, encoded, encoded == null);
511+
TlsRsaPremasterSecretParameterSpec parameterSpec =
512+
(TlsRsaPremasterSecretParameterSpec) spec;
513+
encoded = doFinalForTls(parameterSpec.getClientVersion(),
514+
parameterSpec.getServerVersion());
515+
} else {
516+
encoded = doFinal();
499517
}
500-
501518
return ConstructKeys.constructKey(encoded, algorithm, type);
519+
520+
} catch (BadPaddingException | IllegalBlockSizeException e) {
521+
// BadPaddingException cannot happen for TLS RSA unwrap.
522+
// Neither padding error nor server version error is indicated
523+
// for TLS, but a fake unwrapped value is returned.
524+
// IllegalBlockSizeException cannot happen in any case,
525+
// because of the length check above.
526+
throw new InvalidKeyException("Unwrapping failed", e);
502527
} finally {
503528
if (encoded != null) {
504529
Arrays.fill(encoded, (byte) 0);
505530
}
506531
}
507532
}
508-
509533
// see JCE spec
510534
protected int engineGetKeySize(Key key) throws InvalidKeyException {
511535
RSAKey rsaKey = RSAKeyFactory.toRSAKey(key);

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ private Manifest getManifestFromReference() throws IOException {
199199
jv = new JarVerifier(manEntry.getName(), b);
200200
} else {
201201
if (JarVerifier.debug != null) {
202-
JarVerifier.debug.println("Multiple MANIFEST.MF found. Treat JAR file as unsigned");
202+
JarVerifier.debug.println(
203+
JarVerifier.MULTIPLE_MANIFEST_WARNING);
203204
}
204205
}
205206
}

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

+11-1
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
}

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

+4-1
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

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

+37-7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@
4040
*/
4141
public
4242
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
*/
@@ -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
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public GZIPOutputStream(OutputStream out, int size, boolean syncFlush)
106106
* @exception IOException If an I/O error has occurred.
107107
*/
108108
public GZIPOutputStream(OutputStream out) throws IOException {
109-
this(out, 512, false);
109+
this(out, DeflaterOutputStream.DEFAULT_BUF_SIZE, false);
110110
}
111111

112112
/**
@@ -128,7 +128,7 @@ public GZIPOutputStream(OutputStream out) throws IOException {
128128
public GZIPOutputStream(OutputStream out, boolean syncFlush)
129129
throws IOException
130130
{
131-
this(out, 512, syncFlush);
131+
this(out, DeflaterOutputStream.DEFAULT_BUF_SIZE, syncFlush);
132132
}
133133

134134
/**

0 commit comments

Comments
 (0)