Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime exception on setting cpu and memory restrictions. #27

Closed
appyschool opened this issue Jan 12, 2018 · 5 comments
Closed

Runtime exception on setting cpu and memory restrictions. #27

appyschool opened this issue Jan 12, 2018 · 5 comments

Comments

@appyschool
Copy link

I am consuming this library in a servlet container and it is always throwing the below error on call.

java.lang.RuntimeException: javax.script.ScriptException: SyntaxError: empty range in char class in at line number 1
at delight.nashornsandbox.internal.JsSanitizer.assertScriptEngine(JsSanitizer.java:124)
at delight.nashornsandbox.internal.JsSanitizer.(JsSanitizer.java:114)
at delight.nashornsandbox.internal.NashornSandboxImpl.getSanitizer(NashornSandboxImpl.java:172)
at delight.nashornsandbox.internal.NashornSandboxImpl.eval(NashornSandboxImpl.java:117)

sandbox = NashornSandboxes.create();
sandbox.setMaxCPUTime(100);
sandbox.setMaxMemory(50 * 1024);
sandbox.allowNoBraces(false);
sandbox.setMaxPerparedStatements(30); // because preparing scripts for
// execution is expensive
sandbox.setExecutor(Executors.newSingleThreadExecutor());

in servlet doGet () {


sandbox.eval("function callMe() { return 42; };");
final Object _get = sandbox.get("callMe");

}

mxro pushed a commit that referenced this issue Jan 15, 2018
@mxro
Copy link
Collaborator

mxro commented Jan 15, 2018

Hello There! Thank you for reporting this issue.

Could you have a look at this test case?

I tried to recreate what you are describing. Is the test set up correctly? If I run it, the test succeeds.

@appyschool
Copy link
Author

All the test cases which have cpu or memory monitoring are failing. I have gone through the code and with below changes both test cases and my code is working.

JsSanitizer.java

Line number : 244

try(final BufferedReader reader = new BufferedReader(new InputStreamReader(
new BufferedInputStream(JsSanitizer.class.getClassLoader().getResourceAsStream(BEAUTIFY_JS)), "UTF8"))) {
final StringBuilder sb = new StringBuilder();
String line;
while ((line=reader.readLine()) != null) {
sb.append(line).append('\n');
}
script = sb.toString();
}

mxro pushed a commit that referenced this issue Jan 18, 2018
@mxro
Copy link
Collaborator

mxro commented Jan 18, 2018

That's very interesting! I don't see why specifying the encoding should cause any problems here, so I have added the parameter and released a new version 0.1.4 with this fix to Maven central. Does this solve your issue?

@appyschool
Copy link
Author

Yes, fix is working for me now. Thanks for a quick turnaround.

@mxro
Copy link
Collaborator

mxro commented Jan 21, 2018

That's great! I will close this issue now. If it comes up again, please be free to reopen or submit a different issue!

@mxro mxro closed this as completed Jan 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants