Skip to content

Commit 1f47de5

Browse files
committedJan 20, 2021
8260010: UTF8ZipCoder not thread-safe since JDK-8243469
Reviewed-by: lancea
1 parent 8b95d95 commit 1f47de5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed
 

‎src/java.base/share/classes/java/util/zip/ZipCoder.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2021, 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
@@ -251,8 +251,14 @@ int normalizedHash(byte[] a, int off, int len) {
251251
while (off < end) {
252252
byte b = a[off];
253253
if (b < 0) {
254-
// Non-ASCII, fall back to decoder loop
255-
return normalizedHashDecode(h, a, off, end);
254+
// Non-ASCII, fall back to decoding a String
255+
// We avoid using decoder() here since the UTF8ZipCoder is
256+
// shared and that decoder is not thread safe.
257+
// We also avoid the JLA.newStringUTF8NoRepl variant at
258+
// this point to avoid throwing exceptions eagerly when
259+
// opening ZipFiles (exceptions are expected when accessing
260+
// malformed entries.)
261+
return normalizedHash(new String(a, end - len, len, UTF_8.INSTANCE));
256262
} else {
257263
h = 31 * h + b;
258264
off++;

0 commit comments

Comments
 (0)
Please sign in to comment.