Menu

#23 [3.0-beta2] AIOOBE in string.match with balanced pattern

v3.0-beta1
closed-fixed
nobody
None
5
2015-03-14
2014-02-26
fnuecke
No

The following causes an ArrayIndexOutOfBoundsException:

(""):match("%b''")

It should simply return nil (for no match). The following seems to fix it,
but I cannot really claim to have fully understood the pattern matcher, so
an expert opinion on the patch would be appreciated.

@@ -1155,7 +1155,7 @@ public class StringLib extends TwoArgFunction {
       if ( poff == plen || poff + 1 == plen ) {
         error( "unbalanced pattern" );
       }
-      if ( s.luaByte( soff ) != p.luaByte( poff ) )
+      if ( soff >= s.length() || s.luaByte( soff ) != p.luaByte( poff ) )
         return -1;
       else {
         int b = p.luaByte( poff );

PS: this is in 3.0-beta2.

Discussion

  • Alexander Gladysh

    Any news on this bug? It seems that 3.0 still has it. :-(

     
  • James Roseborough

    A fix for this was check in on 3/9/2014, and the supplied code fragment passes when I test with luaj 3.0, so I believe this is fixed.

    If there is some other pattern that triggers a similar error, please add to the bug report so I can improve the tests.

     
  • James Roseborough

    • status: open --> closed-fixed
     

Log in to post a comment.