Author: Armin Rigo <[email protected]>
Branch: unicode-utf8-re
Changeset: r93249:38318346b17b
Date: 2017-12-03 16:08 +0100
http://bitbucket.org/pypy/pypy/changeset/38318346b17b/

Log:    Be safer against empty-array access

diff --git a/rpython/rlib/rsre/rsre_core.py b/rpython/rlib/rsre/rsre_core.py
--- a/rpython/rlib/rsre/rsre_core.py
+++ b/rpython/rlib/rsre/rsre_core.py
@@ -1194,13 +1194,17 @@
     if string_position >= ctx.end:
         return False
     prefix_len = ctx.pat(5)
-    assert prefix_len >= 0
+    assert prefix_len > 0
     i = 0
     j = 0
-    past_start_positions = [0] * (prefix_len - 1)
+    past_start_positions = [0] * prefix_len
     while True:
         ctx.jitdriver_FastSearch.jit_merge_point(ctx=ctx,
                 string_position=string_position, i=i, prefix_len=prefix_len)
+        past_start_positions[j] = string_position
+        j += 1
+        if j == prefix_len:
+            j = 0
         char_ord = ctx.str(string_position)
         if char_ord != ctx.pat(7 + i):
             if i > 0:
@@ -1224,10 +1228,9 @@
                     if prefix_skip == prefix_len:
                         ptr = ctx.next(ptr)
                 else:
-                    assert prefix_skip < prefix_len - 1
                     j_prefix_skip = j + prefix_skip
-                    if j_prefix_skip >= prefix_len - 1:
-                        j_prefix_skip -= (prefix_len - 1)
+                    if j_prefix_skip >= prefix_len:
+                        j_prefix_skip -= prefix_len
                     ptr = past_start_positions[j_prefix_skip]
                 #flags = ctx.pat(2)
                 #if flags & rsre_char.SRE_INFO_LITERAL:
@@ -1243,10 +1246,6 @@
                     return True
                 overlap_offset = prefix_len + (7 - 1)
                 i = ctx.pat(overlap_offset + i)
-        past_start_positions[j] = string_position
         string_position = ctx.next(string_position)
         if string_position >= ctx.end:
             return False
-        j += 1
-        if j == prefix_len - 1:
-            j = 0
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to