Skip to content

CGI.unescapeHTML => Java::JavaLang::ArrayIndexOutOfBoundsException #4605

@mmmries

Description

@mmmries

Related to #4556

Environment

  • jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae Java HotSpot(TM) 64-Bit Server VM 25.60-b23 on 1.8.0_60-b27 +jit [darwin-x86_64]
  • MacOS Sierra

Expected Behavior

jruby-9.1.7.0 :008 > ::CGI.unescapeHTML(::JSON.parse("{\"str\":\"&#8220GOOD LOVIN&#82\"}")["str"])
=> "&#8220GOOD LOVIN&#82"

Actual Behavior

jruby-9.1.7.0 :008 > ::CGI.unescapeHTML(::JSON.parse("{\"str\":\"&#8220GOOD LOVIN&#82\"}")["str"])
Java::JavaLang::ArrayIndexOutOfBoundsException: 20
	from org.jruby.ext.cgi.escape.CGIEscape.optimized_unescape_html(CGIEscape.java:181)
	from org.jruby.ext.cgi.escape.CGIEscape.cgiesc_unescape_html(CGIEscape.java:372)
	from org.jruby.ext.cgi.escape.CGIEscape$INVOKER$s$1$0$cgiesc_unescape_html.call(CGIEscape$INVOKER$s$1$0$cgiesc_unescape_html.gen)
	from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:338)
	from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:163)
	from org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:315)
	from org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:73)
	from org.jruby.ir.interpreter.Interpreter.INTERPRET_EVAL(Interpreter.java:122)
	from org.jruby.ir.interpreter.Interpreter.evalCommon(Interpreter.java:176)
	from org.jruby.ir.interpreter.Interpreter.evalWithBinding(Interpreter.java:200)
	from org.jruby.RubyKernel.evalCommon(RubyKernel.java:1033)
	from org.jruby.RubyKernel.eval19(RubyKernel.java:1000)
	from org.jruby.RubyKernel$INVOKER$s$0$3$eval19.call(RubyKernel$INVOKER$s$0$3$eval19.gen)
	from org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:77)
	from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:83)
	from org.jruby.ir.instructions.CallBase.interpret(CallBase.java:428)
... 154 levels...
	from org.jruby.internal.runtime.methods.JavaMethod$JavaMethodOneOrNBlock.call(JavaMethod.java:383)
	from org.jruby.internal.runtime.methods.AliasMethod.call(AliasMethod.java:61)
	from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:338)
	from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:163)
	from bin.rails.invokeOther8:require(bin/rails:8)
	from bin.rails.RUBY$script(bin/rails:8)
	from java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
	from org.jruby.ir.Compiler$1.load(Compiler.java:90)
	from org.jruby.Ruby.runScript(Ruby.java:823)
	from org.jruby.Ruby.runNormally(Ruby.java:742)
	from org.jruby.Ruby.runNormally(Ruby.java:760)
	from org.jruby.Ruby.runFromMain(Ruby.java:573)
	from org.jruby.Main.doRunFromMain(Main.java:417)
	from org.jruby.Main.internalRun(Main.java:305)
	from org.jruby.Main.run(Main.java:232)
	from org.jruby.Main.main(Main.java:204)

Similar to the last issue I reported around this, I can't trigger the invalid behavior with a simple copy-paste of the string into IRB, but if I parse it out of a JSON structure (or a protobuf message in my application) then it fails to unescape cleanly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions