mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Merge pull request #19936 from jdconrad/errors
Catch OutOfMemory and StackOverflow errors in Painless
This commit is contained in:
commit
a5008bbb78
@ -127,9 +127,9 @@ public final class PainlessScriptEngineService extends AbstractComponent impleme
|
|||||||
if (value != null) {
|
if (value != null) {
|
||||||
compilerSettings.setPicky(Boolean.parseBoolean(value));
|
compilerSettings.setPicky(Boolean.parseBoolean(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
value = copy.remove(CompilerSettings.INITIAL_CALL_SITE_DEPTH);
|
value = copy.remove(CompilerSettings.INITIAL_CALL_SITE_DEPTH);
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
compilerSettings.setInitialCallSiteDepth(Integer.parseInt(value));
|
compilerSettings.setInitialCallSiteDepth(Integer.parseInt(value));
|
||||||
}
|
}
|
||||||
@ -162,7 +162,8 @@ public final class PainlessScriptEngineService extends AbstractComponent impleme
|
|||||||
return Compiler.compile(loader, scriptName == null ? INLINE_NAME : scriptName, scriptSource, compilerSettings);
|
return Compiler.compile(loader, scriptName == null ? INLINE_NAME : scriptName, scriptSource, compilerSettings);
|
||||||
}
|
}
|
||||||
}, COMPILATION_CONTEXT);
|
}, COMPILATION_CONTEXT);
|
||||||
} catch (Exception e) {
|
// Note that it is safe to catch any of the following errors since Painless is stateless.
|
||||||
|
} catch (OutOfMemoryError | StackOverflowError | Exception e) {
|
||||||
throw convertToScriptException(scriptName == null ? scriptSource : scriptName, scriptSource, e);
|
throw convertToScriptException(scriptName == null ? scriptSource : scriptName, scriptSource, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,8 +119,9 @@ final class ScriptImpl implements ExecutableScript, LeafSearchScript {
|
|||||||
public Object run() {
|
public Object run() {
|
||||||
try {
|
try {
|
||||||
return executable.execute(variables, scorer, doc, aggregationValue);
|
return executable.execute(variables, scorer, doc, aggregationValue);
|
||||||
} catch (PainlessError | BootstrapMethodError | IllegalAccessError | Exception t) {
|
// Note that it is safe to catch any of the following errors since Painless is stateless.
|
||||||
throw convertToScriptException(t);
|
} catch (PainlessError | BootstrapMethodError | OutOfMemoryError | StackOverflowError | Exception e) {
|
||||||
|
throw convertToScriptException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
package org.elasticsearch.painless;
|
package org.elasticsearch.painless;
|
||||||
|
|
||||||
|
import org.apache.lucene.util.Constants;
|
||||||
|
import org.elasticsearch.script.ScriptException;
|
||||||
|
|
||||||
import java.lang.invoke.WrongMethodTypeException;
|
import java.lang.invoke.WrongMethodTypeException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -218,4 +221,17 @@ public class WhenThingsGoWrongTests extends ScriptTestCase {
|
|||||||
exec("BitSet bs = new BitSet(); bs.and(2);");
|
exec("BitSet bs = new BitSet(); bs.and(2);");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testOutOfMemoryError() {
|
||||||
|
assumeTrue("test only happens to work for sure on oracle jre", Constants.JAVA_VENDOR.startsWith("Oracle"));
|
||||||
|
expectScriptThrows(OutOfMemoryError.class, () -> {
|
||||||
|
exec("int[] x = new int[Integer.MAX_VALUE - 1];");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStackOverflowError() {
|
||||||
|
expectScriptThrows(StackOverflowError.class, () -> {
|
||||||
|
exec("void recurse(int x, int y) {recurse(x, y)} recurse(1, 2);");
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user