Skip to content

invalid bytes in ascii string result in ArrayIndexOutOfBoundsException on #chars #1361

@jrochkind

Description

@jrochkind

Simple reproduction:

bad_bytes_ascii = "M\xA1xico".force_encoding("ASCII")
puts bad_bytes_ascii.chars.to_a.length

On MRI, outputs 6.

On jruby 1.7.9 (1.9.3p392) 2013-12-06 87b108a on Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-462-11M4609 [darwin-x86_64],

it raises:

RubyString.java:7337:in `each_charCommon19': java.lang.ArrayIndexOutOfBoundsException: -95
    from RubyString.java:7317:in `chars19'
    from RubyString$INVOKER$i$0$0$chars19_DBG.gen:-1:in `call'
    from JavaMethod.java:458:in `call'
    from RubyClass.java:548:in `finvoke'
    from Helpers.java:491:in `invoke'
    from RubyBasicObject.java:387:in `callMethod'
    from RubyEnumerator.java:274:in `each'
    from RubyEnumerator$INVOKER$i$each_DBG.gen:-1:in `call'
    from RubyClass.java:527:in `finvoke'
    from Helpers.java:479:in `invoke'
    from RubyEnumerable.java:96:in `callEach'
    from RubyEnumerable.java:423:in `to_a19'
    from RubyEnumerable$INVOKER$s$to_a19_DBG.gen:-1:in `call'
    from CachingCallSite.java:306:in `cacheAndCall'
    from CachingCallSite.java:136:in `call'
    from CallNoArgNode.java:60:in `interpret'
    from CallNoArgNode.java:60:in `interpret'
    from FCallOneArgNode.java:36:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from BlockNode.java:71:in `interpret'
    from RootNode.java:129:in `interpret'
    from ASTInterpreter.java:121:in `INTERPRET_ROOT'
    from Ruby.java:838:in `runInterpreter'
    from Ruby.java:846:in `runInterpreter'
    from Ruby.java:677:in `runNormally'
    from Ruby.java:522:in `runFromMain'
    from Main.java:395:in `doRunFromMain'
    from Main.java:290:in `internalRun'
    from Main.java:217:in `run'
    from Main.java:197:in `main'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions