oracle / graaljs

GraalJS – A high-performance, ECMAScript compliant, and embeddable JavaScript runtime for Java
https://www.graalvm.org/javascript/
Universal Permissive License v1.0
1.82k stars 191 forks source link

"10".match(/a*/g) crashes graaljs #835

Closed requiel20 closed 4 months ago

requiel20 commented 4 months ago

Hello,

Bumped into this when trying to migrate a project from Nashorn to graaljs.

Reproduction steps:

js --experimental-options --js.nashorn-compat=true --jvm --vm.Dgraal.DumpOnError=true  

> "10".match(/a*/g)

org.graalvm.polyglot.PolyglotException: java.lang.IllegalArgumentException: got illegal fromIndex value: 3. fromIndex must be >= 0 and <= input length (2)
...

/$/g also crashes, as does /0*$/g

Tested on GraalVM JavaScript (GraalVM CE JVM 24.0.2)

iamstolis commented 4 months ago

Thank you for the report. I can confirm that I am able to reproduce this issue. It seems to happen when ECMAScript version is set to 5 (which is the default value for Nashorn compatibility mode). You can work around that by setting ECMAScript verison to 6 (or later) i.e. by using --ecmascript-version=6.

requiel20 commented 4 months ago

Thank you for the workaround, that is not an option for us sadly as the codebase only works with version 5

jirkamarsik commented 4 months ago

Thanks for the report. The issue is now fixed in https://github.com/oracle/graaljs/commit/ed6d245078c13361beb421c0652a781a0b3970d2 and should make it into the next release.