8216553: JrtFIleSystemProvider getPath(URI) omits /modules element from file path

Reviewed-by: alanb, jlaskey
This commit is contained in:
Athijegannathan Sundararajan 2019-05-28 19:30:30 +05:30
parent 4ff2682a4a
commit 0c724506b8
4 changed files with 61 additions and 7 deletions

View file

@ -190,10 +190,10 @@ public final class JrtFileSystemProvider extends FileSystemProvider {
throw new IllegalArgumentException("Fragment component present");
}
String path = uri.getPath();
if (path == null || path.charAt(0) != '/') {
if (path == null || path.charAt(0) != '/' || path.contains("..")) {
throw new IllegalArgumentException("Invalid path component");
}
return getTheFileSystem().getPath(path);
return getTheFileSystem().getPath("/modules" + path);
}
private FileSystem getTheFileSystem() {

View file

@ -25,6 +25,7 @@
package jdk.internal.jrtfs;
import java.io.File;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -170,7 +171,16 @@ final class JrtPath implements Path {
@Override
public final URI toUri() {
try {
return new URI("jrt", toAbsolutePath().path, null);
String p = toAbsolutePath().path;
if (!p.startsWith("/modules") || p.contains("..")) {
throw new IOError(new RuntimeException(p + " cannot be represented as URI"));
}
p = p.substring("/modules".length());
if (p.isEmpty()) {
p = "/";
}
return new URI("jrt", p, null);
} catch (URISyntaxException ex) {
throw new AssertionError(ex);
}