Nested ZipFileSystems cause issues with URI parsing

Lance Andersen lance.andersen at oracle.com
Sat Jun 6 19:48:12 UTC 2020


Hi Mitchell,

Thank you for your follow up and work on this issue.
> On Jun 6, 2020, at 3:12 PM, Mitchell Skaggs <skaggsm333 at gmail.com> wrote:
> 
> Alan,
> > The file system API doesn't define a format for so-called compound URIs.
> Okay, I just based my fix on the comment describing the syntax as "jar:{uri}!/{entry}".
> > if helps the more general case of N-levels of nesting
> I believe it does resolve the issues with more than 1 level of nesting.
> > there may be other other in the zipfs provider that will need attention too
> Thanks for reminding me, I included another change in my patch below.
> 
> Lance,
> > please generate a diff  and a concise test
> Here's a patch for the fix:
> 
> diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java
> --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java
> +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java
> @@ -69,7 +69,7 @@
>          try {
>              // only support legacy JAR URL syntax  jar:{uri}!/{entry} for now
>              String spec = uri.getRawSchemeSpecificPart();
> -            int sep = spec.indexOf("!/");
> +            int sep = spec.lastIndexOf("!/");
>              if (sep != -1) {
>                  spec = spec.substring(0, sep);
>              }
> @@ -134,7 +134,7 @@
>      @Override
>      public Path getPath(URI uri) {
>          String spec = uri.getSchemeSpecificPart();
> -        int sep = spec.indexOf("!/");
> +        int sep = spec.lastIndexOf("!/");
>          if (sep == -1)
>              throw new IllegalArgumentException("URI: "
>                  + uri
> 
> I have a test, but I'm not sure where to put it and how to build everything on Windows. Here's a "vanilla" version of the test that demonstrates the issue:

Please see: open/test/jdk/jdk/nio/zipfs/testng/test/ChannelTests.java  or open/test/jdk/jdk/nio/zipfs/CopyMoveTests.java as an example of  creating a test using TestNG (the test will also run outside of the JDK environment)
> 
> Path zip1Path = Files.createTempFile("zip1", ".zip");
> try {
>     Files.delete(zip1Path);
>     try (FileSystem zip1 = FileSystems.newFileSystem(zip1Path, Map.of("create", true))) {
>         Path zip2Path = zip1.getPath("zip2.zip");
>         try (FileSystem zip2 = FileSystems.newFileSystem(zip2Path, Map.of("create", true))) {
>             Path nestedFilePath = zip2.getPath("test.txt");
>             Path newPath = Path.of(nestedFilePath.toUri());
>             assert nestedFilePath.equals(newPath);
>         }
>     }
> } finally {
>     try (Stream<Path> walk = Files.walk(zip1Path)) {
>         walk.sorted(Comparator.reverseOrder())
>                 .forEach(path -> {
>                     try {
>                         Files.delete(path);
>                     } catch (IOException e) {
>                         throw new Error(e);
>                     }
>                 });
>     }
> }
> 
> It builds a nested zip file in the system's temp directory, verifies the path is parsed correctly, and deletes it when finished.
For the tests, best to create any files, such as Zip files, in the  work directory as the test runs (see the example or similar tests in the Zip FS test directory mentioned above).

Please see https://openjdk.java.net/jtreg/ for additional info on JTreg
> 
> If you need me to build and test everything, I can transfer it to a linux machine and do it there; it'll just take some time to get a build environment set up.
Certainly having a build environment would be beneficial for future contributions and testing, but that is really up to you.
> 
> Thanks,
> Mitchell
> 

Best,
Lance

 <http://oracle.com/us/design/oracle-email-sig-198324.gif>
 <http://oracle.com/us/design/oracle-email-sig-198324.gif> <http://oracle.com/us/design/oracle-email-sig-198324.gif>
 <http://oracle.com/us/design/oracle-email-sig-198324.gif>Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
Oracle Java Engineering 
1 Network Drive 
Burlington, MA 01803
Lance.Andersen at oracle.com <mailto:Lance.Andersen at oracle.com>



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20200606/4c3a5d38/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: oracle_sig_logo.gif
Type: image/gif
Size: 658 bytes
Desc: not available
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20200606/4c3a5d38/oracle_sig_logo.gif>


More information about the nio-dev mailing list