graal icon indicating copy to clipboard operation
graal copied to clipboard

Ignore permitted languages that aren't present in sandbox check

Open SirYwell opened this issue 2 years ago • 6 comments

Consider following method:

    private static void createContext(SandboxPolicy policy) {
        Context.newBuilder("myMissingLang") // myMissingLang is not present
                .sandbox(policy)
                .in(InputStream.nullInputStream())
                .out(OutputStream.nullOutputStream())
                .err(OutputStream.nullOutputStream())
                .build();
    }

Running createContext(SandboxPolicy.TRUSTED) will run without exceptions, while createContext(SandboxPolicy.CONSTRAINED) currently throws the following exception:

Exception in thread "main" org.graalvm.polyglot.PolyglotException: java.lang.NullPointerException: Cannot invoke "com.oracle.truffle.polyglot.PolyglotLanguage.validateSandbox(org.graalvm.polyglot.SandboxPolicy)" because the return value of "java.util.Map.get(Object)" is null
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.validateSandbox(PolyglotEngineImpl.java:2209)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.<init>(PolyglotEngineImpl.java:339)
	at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotImpl.buildEngine(PolyglotImpl.java:283)
	at com.oracle.graal.graal_enterprise/com.oracle.truffle.polyglot.enterprise.EnterprisePolyglotImpl.buildEngine(stripped:136)
	at org.graalvm.sdk/org.graalvm.polyglot.Engine$Builder.build(Engine.java:681)
	at org.graalvm.sdk/org.graalvm.polyglot.Context$Builder.build(Context.java:1926)

This PR avoids the NPE by ignoring entries in the permittedLanguages array that don't have a matching language installed. This way, the behavior is the same for all sandbox policies.

SirYwell avatar Aug 02 '23 18:08 SirYwell

Thank you for contributing to GraalVM, @chumer can you please assign someone to review this PR?

oubidar-Abderrahim avatar Aug 09 '23 14:08 oubidar-Abderrahim

Tests for this are needed in SandboxPolicyTest. But we can take it from here. Thank you for the report! cc @tzezula

chumer avatar Aug 09 '23 15:08 chumer

Please let me know if there is something to do from my side. Thanks!

SirYwell avatar Aug 22 '23 06:08 SirYwell

@SirYwell sorry for the delay. We are currently very busy, but we can hopefully pick this up soon. I assume this is not a blocker for you, right?

chumer avatar Aug 22 '23 10:08 chumer

@SirYwell sorry for the delay. We are currently very busy, but we can hopefully pick this up soon. I assume this is not a blocker for you, right?

That's totally fine! I just wanted to make sure there's nothing to do from my side right now.

SirYwell avatar Aug 22 '23 12:08 SirYwell

Any news on this?

SirYwell avatar Aug 02 '24 18:08 SirYwell