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

Parser does not seem to terminate when parsing this string #4728

jsyeo opened this issue Jul 31, 2017 · 1 comment

Parser does not seem to terminate when parsing this string #4728

jsyeo opened this issue Jul 31, 2017 · 1 comment


Copy link

jsyeo commented Jul 31, 2017


My ruby -v says:

jruby (2.3.3) 2017-06-15 33c6439 Java HotSpot(TM) 64-Bit Server VM 25.131-b11 on 1.8.0_131-b11 +jit [darwin-x86_64]

And I am using OS X 10.12.6.

Actual Behavior

When reading a file that contains this comment:

    #     policy: "\"Version\": \"2012-10-17\",\n    \"Id\": \"custom-policy-2016-12-07\",\n    \"Statement\": [\n        {\n            \"Sid\": \"Enable IAM User Permissions\",\n            \"Effect\": \"Allow\",\n            \"Principal\": {\n                \"AWS\": \"arn:aws:iam::111122223333:root\"\n            },\n            \"Action\": \"kms:*\",\n            \"Resource\": \"*\"\n        },\n        {\n            \"Sid\": \"Allow access for Key Administrators\",\n            \"Effect\": \"Allow\",\n            \"Principal\": {\n                \"AWS\": [\n                    \"arn:aws:iam::111122223333:user/ExampleAdminUser\",\n                    \"arn:aws:iam::111122223333:role/ExampleAdminRole\"\n                ]\n            },\n            \"Action\": [\n                \"kms:Create*\",\n                \"kms:Describe*\",\n                \"kms:Enable*\",\n                \"kms:List*\",\n                \"kms:Put*\",\n                \"kms:Update*\",\n               

The jruby interpreter seems to run forever. Even when I have removed everything from the ruby file except for this line, it still seems to not terminate when parsing this particular string.

Here's the stack trace of the non-terminating code when I've tried to dump the running thread:

"main@1" prio=5 tid=0x1 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
	  at org.joni.ByteCodeMachine.matchAt(
	  at org.joni.Matcher.matchCheck(
	  at org.joni.Matcher.searchInterruptible(
	  at org.jruby.RubyRegexp$
	  at org.jruby.RubyRegexp$
	  at org.jruby.RubyThread.executeTask(
	  at org.jruby.RubyRegexp.matcherSearch(
	  at org.jruby.lexer.LexingCommon.parseMagicComment(
	  at org.jruby.lexer.yacc.RubyLexer.yylex(
	  at org.jruby.lexer.yacc.RubyLexer.nextToken(
	  at org.jruby.parser.RubyParser.yyparse(
	  at org.jruby.parser.RubyParser.yyparse(
	  at org.jruby.parser.RubyParser.parse(
	  at org.jruby.parser.Parser.parse(
	  at org.jruby.parser.Parser.parse(
	  at org.jruby.Ruby.parseFileAndGetAST(
	  at org.jruby.Ruby.parseFileFromMainAndGetAST(
	  at org.jruby.Ruby.parseFileFromMain(
	  at org.jruby.Ruby.parseFromMain(
	  at org.jruby.Ruby.runFromMain(
	  at org.jruby.Main.doRunFromMain(
	  at org.jruby.Main.internalRun(
	  at org.jruby.Main.main(

Hopefully that helps. 😉

Expected Behavior

MRI seems to parse this line properly and terminates immediately.

@enebo enebo added the parser label Jul 31, 2017
@enebo enebo added this to the JRuby milestone Jul 31, 2017
Copy link

enebo commented Jul 31, 2017

@jsyeo thanks for reporting this. The lexer processes comment lines looking for magic comment pragmas and we use a regexp. I am guessing something about this string causes our regexp engine to behave pathologically. This definitely helps since it gives a realistic line where we choke.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants