RFR: 8251329: (zipfs) Files.walkFileTree walks infinitely if zip has dir named "." inside
Jaikiran Pai
jpai at openjdk.java.net
Mon Jul 26 09:55:07 UTC 2021
On Sun, 25 Jul 2021 21:56:10 GMT, Lance Andersen <lancea at openjdk.org> wrote:
> Hi,
>
> As discussed in the https://mail.openjdk.java.net/pipermail/core-libs-dev/2021-July/079621.html thread, this is the revised patch to address the use of '.' and '..' within Zip FS
>
> Zip FS needs to use "." and ".." as links to the current and parent directories and cannot reliably support entries that have "." and ".." as name elements. This patch updates Zip Fs to reject ZIP files that have entries in the CEN that can't be used for files in a file system.
>
>
> Mach5 tiers 1 through 3 have been run without any errors encountered .
>
> Best,
> Lance
This change looks fine to me. I was unsure how the writing/creating entries with `.` or `..` with `ZipFileSystem` would behave in context of this change, so I gave this a try locally with the changes from this PR:
try (FileSystem zipfs = FileSystems.newFileSystem(ZIPFILE)) {
final Path[] paths = new Path[]{
zipfs.getPath("./Hello.txt"),
zipfs.getPath("../../../Hello.txt"),
zipfs.getPath("../Hello.txt")};
for (int i = 0; i < paths.length; i++) {
try (OutputStream os = Files.newOutputStream(paths[i])) {
os.write(("Hello " + i).getBytes(StandardCharsets.UTF_8));
}
}
}
This code runs fine and it ends up creating (just one) CEN entry for `Hello.txt`:
JTwork/scratch/zipfsDotDotTest.zip
Length Date Time Name
--------- ---------- ----- ----
7 07-26-2021 15:07 Hello.txt
In other words, the `ZipFileSystem` doesn't end up creating a zip file which is then rejected by `ZipFileSystem` when creating a new filesystem using `Files.newFileSystem`. That's a good thing.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4900
More information about the nio-dev
mailing list