From 4222c5b8ce9df6403a5abadd6a088b4d7214f4e6 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 12 Jun 2019 12:53:16 +0100 Subject: [PATCH] Prevent URLResource and JarURLConnection from leaking an InputStream Fixes gh-17121 --- .../boot/web/embedded/undertow/JarResourceManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/JarResourceManager.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/JarResourceManager.java index 3f7ad6909ba..d118d99412b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/JarResourceManager.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/JarResourceManager.java @@ -26,6 +26,8 @@ import io.undertow.server.handlers.resource.ResourceChangeListener; import io.undertow.server.handlers.resource.ResourceManager; import io.undertow.server.handlers.resource.URLResource; +import org.springframework.util.StringUtils; + /** * {@link ResourceManager} for JAR resources. * @@ -48,7 +50,7 @@ class JarResourceManager implements ResourceManager { public Resource getResource(String path) throws IOException { URL url = new URL("jar:file:" + this.jarPath + "!" + (path.startsWith("/") ? path : "/" + path)); URLResource resource = new URLResource(url, path); - if (resource.getContentLength() < 0) { + if (StringUtils.hasText(path) && !"/".equals(path) && resource.getContentLength() < 0) { return null; } return resource;