-
CSR
-
Resolution: Approved
-
P4
-
None
-
behavioral
-
minimal
-
There is minimal risk with this change as very few Zip files include a zip file comment and we have not had any previous reports of ZipFile::getComment throwing an Exception
-
Java API
Summary
An IllegalArgumentException may be thrown by ZipFile::getComment if there is a problem decoding the bytes representing the Zip file comment.
Problem
ZipFile::getComment may throw an IllegalArgumentException if an error occurs when decoding the bytes which represent the Zip file comment. Unfortunately the specification for ZipFile::getComment does not specify that this method may throw an Exception.
Solution
In the event of an exception when decoding the byte array that represents the Zip file comment, ZipFile::getComment will now return null instead of a spurious IllegalArgumentException.
Specification
The ZipFile::getComment specification will be updated to the following
diff --git a/src/java.base/share/classes/java/util/zip/ZipFile.java b/src/java.base/share/classes/java/util/zip/ZipFile.java
index 7281db3297b..dd8e8126c76 100644
--- a/src/java.base/share/classes/java/util/zip/ZipFile.java
+++ b/src/java.base/share/classes/java/util/zip/ZipFile.java
@@ -305,7 +305,9 @@ public ZipFile(File file, Charset charset) throws IOException
}
/**
- * Returns the zip file comment, or null if none.
+ * Returns the zip file comment. If a comment does not exist or an error is
+ * encountered decoding the comment using the charset specified
+ * when opening the Zip file, then {@code null} is returned.
*
* @return the comment string for the zip file, or null if none
*
@@ -319,7 +321,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;
+ }
}
}
- csr of
-
JDK-8321156 Improve the handling of invalid UTF-8 byte sequences for ZipInputStream::getNextEntry and ZipFile::getComment
- Closed