Fix Tomcat TldScanner issues by returning raw zip data for nested jars

Update JarUrlConnection so that the full raw zip data is returned from
nested jars when no entry name is specified. This update allows
Tomcat's `WarURLConnection` to work with our nested connections since
they can parse the returned raw zip data.

Fixes gh-38047
This commit is contained in:
Phillip Webb
2023-10-26 18:58:15 -07:00
parent bba323ba5f
commit 4af9ed4d1d
4 changed files with 60 additions and 9 deletions

View File

@@ -22,6 +22,7 @@ import java.io.FileOutputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
@@ -237,8 +238,8 @@ class JarUrlConnectionTests {
}
@Test
void getInputStreamWhenHasNoEntryThrowsException() throws Exception {
JarUrlConnection connection = JarUrlConnection.open(this.url);
void getInputStreamWhenNotNestedAndHasNoEntryThrowsException() throws Exception {
JarUrlConnection connection = JarUrlConnection.open(JarUrl.create(this.file));
assertThatIOException().isThrownBy(() -> connection.getInputStream()).withMessage("no entry name specified");
}
@@ -271,6 +272,18 @@ class JarUrlConnectionTests {
.withMessageContaining("JAR entry missing.dat not found in");
}
@Test // gh-38047
void getInputStreamWhenNoEntryAndNestedReturnsFullJarInputStream() throws Exception {
JarUrlConnection connection = JarUrlConnection.open(JarUrl.create(this.file, "nested.jar"));
File outFile = new File(this.temp, "out.zip");
try (OutputStream out = new FileOutputStream(outFile)) {
connection.getInputStream().transferTo(out);
}
try (JarFile outJar = new JarFile(outFile)) {
assertThat(outJar.getEntry("3.dat")).isNotNull();
}
}
@Test
void getInputStreamReturnsInputStream() throws IOException {
JarUrlConnection connection = JarUrlConnection.open(JarUrl.create(this.file, "nested.jar", "3.dat"));