Skip to content

Fat jar launcher mishandles root jar files with + characters in their path, making nested entries unloadable #17208

Closed
@asibross

Description

@asibross

When a URL contains a special character such as +, the call getRootJarFileFromUrl fails.
Here is a sample repro:

public static void main(String[] args) throws IOException {
    URL url = new URL("jar:file:/tmp/test/test+1.jar!/META-INF/MANIFEST.MF");
    JarFile jarFile = new Handler().getRootJarFileFromUrl(url);
}

This is the exception:

Exception in thread "main" java.io.IOException: Unable to open root Jar file 'file:/tmp/test/test+1.jar'
	at org.springframework.boot.loader.jar.Handler.getRootJarFile(Handler.java:324)
	at org.springframework.boot.loader.jar.Handler.getRootJarFileFromUrl(Handler.java:305)
	at Main.main(Main.java:11)
Caused by: java.lang.IllegalArgumentException: File /tmp/test/test 1.jar must exist
	at org.springframework.boot.loader.data.RandomAccessDataFile$FileAccess.openIfNecessary(RandomAccessDataFile.java:234)
	at org.springframework.boot.loader.data.RandomAccessDataFile$FileAccess.<init>(RandomAccessDataFile.java:216)
	at org.springframework.boot.loader.data.RandomAccessDataFile$FileAccess.<init>(RandomAccessDataFile.java:206)
	at org.springframework.boot.loader.data.RandomAccessDataFile.<init>(RandomAccessDataFile.java:49)
	at org.springframework.boot.loader.jar.JarFile.<init>(JarFile.java:88)
	at org.springframework.boot.loader.jar.Handler.getRootJarFile(Handler.java:318)
	... 2 more

I believe the root cause is the decoding of the root path that happens here.
The returned String from decode omits the special character.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions