RFR: JDK-8197398, (zipfs) Files.walkFileTree walk indefinitelly while processing JAR file with "/" as a directory inside.
Hi, Please help review the proposed change for JDK-8197398. issue: https://bugs.openjdk.java.net/browse/JDK-8197398 webrev: http://cr.openjdk.java.net/~sherman/8197398/webrev A little background: The existing zipfs has an assumption that the "normal/healthy/secured" zip/jar file should not include any entry that has an absolute path, root "/" included. Various jar/zip tools have been fixed/patched in the past years to avoid create such a jar/zip file for security reason. But there are zip/jar files in the wild that do include absolute paths and do include a "/" root sometime, the offending jar file included in the bug report is just one of those. With this "wrong" assumption, the existing zipfs implementation always add a pseudo root directory before building the internal inode tree and unfortunately attaches the "real" root entry (exists in the jar/zip file) to be its child, in which trigger a circle when iteration. The proposed change is to solve this problem by only adding the pseudo root when there is no real root in the zip/jar file. Further the proposed change will try to "normalize" the zip/jar file when it has any update needs to sync/write the update to the underlying zip/jar file when closing, by removing any absolute path for all the entries, root "/" included, with the assumption that the zipfis implementation should never create/generate an unsecured zip/jar file. Thanks, Sherman
On 29/08/2018 03:09, Xueming Shen wrote:
Hi,
Please help review the proposed change for JDK-8197398.
issue: https://bugs.openjdk.java.net/browse/JDK-8197398 webrev: http://cr.openjdk.java.net/~sherman/8197398/webrev
A little background:
The existing zipfs has an assumption that the "normal/healthy/secured" zip/jar file should not include any entry that has an absolute path, root "/" included. Various jar/zip tools have been fixed/patched in the past years to avoid create such a jar/zip file for security reason. But there are zip/jar files in the wild that do include absolute paths and do include a "/" root sometime, the offending jar file included in the bug report is just one of those. The approach looks okay, I think just wonder if the test could be expanded to cover entry with repeated leading slashes.
One nit is that hasAbsolutePath (and also the existing readOnly) aren't final. One suggestion is for initCEN to return a CEN object that defines array() and hasAbsolutePath() methods that you can use in the constructor for the initializing the final fields. -Alan
On 8/29/18, 3:22 AM, Alan Bateman wrote:
The approach looks okay, I think just wonder if the test could be expanded to cover entry with repeated leading slashes.
One nit is that hasAbsolutePath (and also the existing readOnly) aren't final. One suggestion is for initCEN to return a CEN object that defines array() and hasAbsolutePath() methods that you can use in the constructor for the initializing the final fields.
It appears it's not necessary to have the "hasAbsolutePath" and pay the price to check in initCEN(). I managed to do it locally inside copyLOCEntry(...). http://cr.openjdk.java.net/~sherman/8197398/webrev/ Regarding "repeated leading slashes", I think you are opening another door for further enhancement. We are not doing any real path normalization in ZipFileSystem for its existing entry path, other than padding a "/" to make it like a normal path, mainly for better performance when doing path lookup (while we do the normal normalization in ZipPath for String from external). The zip spec basically does not specify anything regarding the canonical form of its entry path normalization, exception "the entry is a dir if ends with a '/'. So it might be an interesting RFE. the trade off is to have a more "complicated" logic somewhere during the initialization. Sherman
On 29/08/2018 22:56, Xueming Shen wrote:
It appears it's not necessary to have the "hasAbsolutePath" and pay the price to check in initCEN(). I managed to do it locally inside copyLOCEntry(...).
This approach looks good. -Alan
participants (2)
-
Alan Bateman
-
Xueming Shen