8224946: jrtfs URI to Path and Path to URI conversions are wrong

Reviewed-by: alanb
This commit is contained in:
Athijegannathan Sundararajan 2019-05-30 17:30:33 +05:30
parent 3ab3ffd29f
commit 90fb4990ed
6 changed files with 64 additions and 9 deletions

View file

@ -190,10 +190,11 @@ 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);
}