Skip to content
Permalink
Browse files
8260010: UTF8ZipCoder not thread-safe since JDK-8243469
Backport-of: 1f47de5f6a3969ab2bdd1330ffbb4a9a572f7074
  • Loading branch information
cl4es committed Jan 25, 2021
1 parent d3ecad7 commit 834962bc701e31f06a94e0206cd00c22ffdfec82
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/java.base/share/classes/java/util/zip/ZipCoder.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -224,8 +224,14 @@ int normalizedHash(byte[] a, int off, int len) {
while (off < end) {
byte b = a[off];
if (b < 0) {
// Non-ASCII, fall back to decoder loop
return normalizedHashDecode(h, a, off, end);
// Non-ASCII, fall back to decoding a String
// We avoid using decoder() here since the UTF8ZipCoder is
// shared and that decoder is not thread safe.
// We also avoid the JLA.newStringUTF8NoRepl variant at
// this point to avoid throwing exceptions eagerly when
// opening ZipFiles (exceptions are expected when accessing
// malformed entries.)
return normalizedHash(new String(a, end - len, len, UTF_8.INSTANCE));
} else {
h = 31 * h + b;
off++;

1 comment on commit 834962b

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 834962b Jan 25, 2021

Please sign in to comment.