Skip to content

Commit 1f5b29b

Browse files
committed
[GR-60143] ReadOnlyFileSystem.newByteChannel fails for regular file if openOptions contains NOFOLLOW_LINKS.
1 parent ad42202 commit 1f5b29b

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/FileSystemsTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.io.BufferedWriter;
4747
import java.io.Closeable;
4848
import java.io.IOException;
49+
import java.io.InputStreamReader;
4950
import java.io.OutputStream;
5051
import java.lang.reflect.Constructor;
5152
import java.lang.reflect.Method;
@@ -464,6 +465,41 @@ protected Object execute(RootNode node, Env env, Object[] contextArguments, Obje
464465
}
465466
}
466467

468+
@Test
469+
public void testReadIgnoresLinkOption() {
470+
Context ctx = cfg.getContext();
471+
String configuration = cfg.getName();
472+
String path = cfg.getPath().toString();
473+
boolean usePublicFile = cfg.usePublicFile;
474+
boolean canRead = cfg.canRead();
475+
AbstractExecutableTestLanguage.evalTestLanguage(ctx, TestReadIgnoresLinkOptionLanguage.class, "", configuration, path, usePublicFile, canRead);
476+
}
477+
478+
@Registration
479+
public static final class TestReadIgnoresLinkOptionLanguage extends AbstractExecutableTestLanguage {
480+
@Override
481+
@TruffleBoundary
482+
protected Object execute(RootNode node, Env env, Object[] contextArguments, Object[] frameArguments) throws Exception {
483+
String configurationName = (String) contextArguments[0];
484+
String path = (String) contextArguments[1];
485+
boolean usePublicFile = (boolean) contextArguments[2];
486+
boolean canRead = (boolean) contextArguments[3];
487+
TruffleFile file = resolve(env, usePublicFile, path, FOLDER_EXISTING, FILE_EXISTING);
488+
try {
489+
try (BufferedReader in = new BufferedReader(new InputStreamReader(file.newInputStream(LinkOption.NOFOLLOW_LINKS), StandardCharsets.UTF_8))) {
490+
final String content = in.readLine();
491+
Assert.assertTrue(formatErrorMessage("Expected SecurityException", configurationName, path), canRead);
492+
Assert.assertEquals(formatErrorMessage("Expected file content", configurationName, path), FILE_EXISTING_CONTENT, content);
493+
}
494+
} catch (SecurityException se) {
495+
Assert.assertFalse(formatErrorMessage("Unexpected SecurityException", configurationName, path), canRead);
496+
} catch (IOException ioe) {
497+
throw new AssertionError(formatErrorMessage(ioe.getMessage(), configurationName, path), ioe);
498+
}
499+
return null;
500+
}
501+
}
502+
467503
@Test
468504
public void testReadUsingStream() {
469505
Context ctx = cfg.getContext();

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/FileSystems.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,12 +1524,13 @@ private static class ReadOnlyFileSystem extends DeniedIOFileSystem {
15241524
AccessMode.READ,
15251525
AccessMode.EXECUTE);
15261526

1527-
private static final List<StandardOpenOption> READ_OPTIONS = Arrays.asList(
1527+
private static final Set<? extends OpenOption> READ_OPTIONS = Set.of(
15281528
StandardOpenOption.READ,
15291529
StandardOpenOption.DSYNC,
15301530
StandardOpenOption.SPARSE,
15311531
StandardOpenOption.SYNC,
1532-
StandardOpenOption.TRUNCATE_EXISTING);
1532+
StandardOpenOption.TRUNCATE_EXISTING,
1533+
LinkOption.NOFOLLOW_LINKS);
15331534

15341535
private final FileSystem delegateFileSystem;
15351536

0 commit comments

Comments
 (0)