Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZipFileSystem throws "java.util.zip.ZipException: read CEN tables failed" with certain nested jars #38595

Closed
philwebb opened this issue Nov 29, 2023 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@philwebb
Copy link
Member

Initially raised in #38592 (comment)

FileSystems.getFileSystem(URI.create("jar:nested:/Users/rdehuyss/Projects/Personal/jobrunr/examples/example-java-mag/target/example-java-mag-1.0-SNAPSHOT.jar"));

throws the following exception (which I can understand from the docs as it is the new format to retrieve resources):

java.lang.IllegalArgumentException: 'path' must contain '/!'
        at org.springframework.boot.loader.net.protocol.nested.NestedLocation.parse(NestedLocation.java:98)
        at org.springframework.boot.loader.net.protocol.nested.NestedLocation.fromUri(NestedLocation.java:89)
        at org.springframework.boot.loader.nio.file.NestedFileSystemProvider.getPath(NestedFileSystemProvider.java:88)
        at java.base/java.nio.file.Path.of(Path.java:208)
        at java.base/java.nio.file.Paths.get(Paths.java:98)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.uriToPath(ZipFileSystemProvider.java:76)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:98)
        at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:339)
        at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:288)

However,

FileSystems.newFileSystem(URI.create("jar:nested:/Users/rdehuyss/Projects/Personal/jobrunr/examples/example-java-mag/target/example-java-mag-1.0-SNAPSHOT.jar/!BOOT-INF/lib/jobrunr-1.0.0-SNAPSHOT.jar"), Collections.emptyMap());

throws the following exception:

java.util.zip.ZipException: read CEN tables failed
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.initCEN(ZipFileSystem.java:1549)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystem.<init>(ZipFileSystem.java:174)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getZipFileSystem(ZipFileSystemProvider.java:125)
        at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:106)
        at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:339)
        at java.base/java.nio.file.FileSystems.newFileSystem(FileSystems.java:288)
@philwebb
Copy link
Member Author

It looks like ZipFileSystem and NestedFileSystem disagree about the contract of ReadableByteChannel.read.

The nested file system expects that the call can return less bytes than remain in the buffer and the caller will make repeated calls until they're all read. This was because the Javadoc of ReadableByteChannel.read states:

A read operation might not fill the buffer, and in fact it might not read any bytes at all

The ZipFileSystem however has this check if (readFullyAt(cen, 0, cen.length, cenpos) != end.cenlen + ENDHDR). The readFullyAt method does return ch.position(pos).read(bb); which clearly doesn't deal a read that doesn't return everything.

@philwebb philwebb self-assigned this Nov 29, 2023
@philwebb philwebb added the type: bug A general bug label Nov 29, 2023
@philwebb philwebb added this to the 3.2.1 milestone Nov 29, 2023
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Dec 10, 2023
Spring Boot 3.2 changed the URL format of their nested jars[1] to be
more compliant with JDK expectations. They now represented nested jars
as their own `nested` scheme rather than the `file` scheme. This allows
these URLs to be used seamlessly with `FileSystems.newFileSystem`.

Unfortunately the workarounds for Spring Boot 3.1 did not account for
this.

Additionally, our jar uri parsing assumed naively that there would only
be a single `!/` in a regular jar uri. However, jar uris are
recursively defined as[2]:

```
jar:<url>!/[<entry>]
```

And while this should allow Cucumber to discover resources in nested
jars as well it does seem that Spring Boot 3.2 still has some issues[3].

1. https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes
2. https://www.iana.org/assignments/uri-schemes/prov/jar
3. spring-projects/spring-boot#38595
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Dec 10, 2023
Spring Boot 3.2 changed the URL format of their nested jars[1] to be
more compliant with JDK expectations. They now represented nested jars
as their own `nested` scheme rather than the `file` scheme. This allows
these URLs to be used seamlessly with `FileSystems.newFileSystem`.

Unfortunately the workarounds for Spring Boot 3.1 did not account for
this.

Additionally, our jar uri parsing assumed naively that there would only
be a single `!/` in a regular jar uri. However, jar uris are
recursively defined as[2]:

```
jar:<url>!/[<entry>]
```

And while this should allow Cucumber to discover resources in nested
jars as well it does seem that Spring Boot 3.2 still has some issues[3].

Closes: #2828

1. https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes
2. https://www.iana.org/assignments/uri-schemes/prov/jar
3. spring-projects/spring-boot#38595
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Dec 10, 2023
Spring Boot 3.2 changed the URL format of their nested jars[1] to be
more compliant with JDK expectations. They now represented nested jars
as their own `nested` scheme rather than the `file` scheme. This allows
these URLs to be used seamlessly with `FileSystems.newFileSystem`.

Unfortunately the workarounds for Spring Boot 3.1 did not account for
this.

Additionally, our jar uri parsing assumed naively that there would only
be a single `!/` in a regular jar uri. However, jar uris are
recursively defined as[2]:

```
jar:<url>!/[<entry>]
```

And while this should allow Cucumber to discover resources in nested
jars as well it does seem that Spring Boot 3.2 still has some issues[3].

Closes: #2828

1. https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes
2. https://www.iana.org/assignments/uri-schemes/prov/jar
3. spring-projects/spring-boot#38595
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Dec 11, 2023
Spring Boot 3.2 changed the URL format of their nested jars[1] to be
more compliant with JDK expectations. They now represented nested jars
as their own `nested` scheme rather than the `file` scheme. This allows
these URLs to be used seamlessly with `FileSystems.newFileSystem`.

Unfortunately the workarounds for Spring Boot 3.1 did not account for
this.

Additionally, our jar uri parsing assumed naively that there would only
be a single `!/` in a regular jar uri. However, jar uris are
recursively defined as[2]:

```
jar:<url>!/[<entry>]
```

And while this should allow Cucumber to discover resources in nested
jars as well it does seem that Spring Boot 3.2 still has some issues[3].

Closes: #2828

1. https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes
2. https://www.iana.org/assignments/uri-schemes/prov/jar
3. spring-projects/spring-boot#38595
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant