Author: Ronan Lamy <[email protected]>
Branch: py3.5
Changeset: r92960:1233d5aa782f
Date: 2017-11-07 18:38 +0000
http://bitbucket.org/pypy/pypy/changeset/1233d5aa782f/

Log:    Bail early in .startswith() and .endswith() is start is past the end
        of the string.

        This prevents an overflow, followed by a segfault, in
        rpython.rlib.rstring.startswith() when start is close to sys.maxint.

diff --git a/pypy/objspace/std/stringmethods.py 
b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -628,6 +628,8 @@
 
     def _startswith(self, space, value, w_prefix, start, end):
         prefix = self._op_val(space, w_prefix)
+        if start > len(value):
+            return False
         return startswith(value, prefix, start, end)
 
     def descr_endswith(self, space, w_suffix, w_start=None, w_end=None):
@@ -653,6 +655,8 @@
 
     def _endswith(self, space, value, w_prefix, start, end):
         prefix = self._op_val(space, w_prefix)
+        if start > len(value):
+            return False
         return endswith(value, prefix, start, end)
 
     def _strip(self, space, w_chars, left, right, name='strip'):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to