Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/java.base/share/classes/java/util/zip/ZipFile.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2024, 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
Expand Down Expand Up @@ -319,7 +319,13 @@ public String getComment() {
if (res.zsrc.comment == null) {
return null;
}
return res.zsrc.zc.toString(res.zsrc.comment);
// If there is a problem decoding the byte array which represents
// the Zip file comment, return null;
try {
return res.zsrc.zc.toString(res.zsrc.comment);
} catch (IllegalArgumentException iae) {
return null;
}
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/java.base/share/classes/java/util/zip/ZipInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,16 @@ private ZipEntry readLOC() throws IOException {
}
readFully(b, 0, len);
// Force to use UTF-8 if the USE_UTF8 bit is ON
ZipEntry e = createZipEntry(((flag & USE_UTF8) != 0)
? ZipCoder.toStringUTF8(b, len)
: zc.toString(b, len));
String entryName;
try {
entryName = ((flag & USE_UTF8) != 0) ?
ZipCoder.toStringUTF8(b, len)
: zc.toString(b, len);
} catch (Exception ex) {
throw (ZipException) new ZipException(
"invalid LOC header (bad entry name)").initCause(ex);
}
ZipEntry e = createZipEntry(entryName);
// now get the remaining fields for the entry
if ((flag & 1) == 1) {
throw new ZipException("encrypted ZIP entry not supported");
Expand Down
Loading