Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: py3.5
Changeset: r93236:981544a8f028
Date: 2017-12-02 03:12 +0000
http://bitbucket.org/pypy/pypy/changeset/981544a8f028/

Log:    fix: StringIO.seek() may set the position beyond the end of the
        buffer

diff --git a/pypy/module/_io/interp_stringio.py 
b/pypy/module/_io/interp_stringio.py
--- a/pypy/module/_io/interp_stringio.py
+++ b/pypy/module/_io/interp_stringio.py
@@ -35,7 +35,8 @@
     def _convert_limit(self, limit):
         if limit < 0 or limit > len(self.data) - self.pos:
             limit = len(self.data) - self.pos
-        assert limit >= 0
+            if limit < 0:  # happens when self.pos > len(self.data)
+                limit = 0
         return limit
 
     def readline_universal(self, limit):
diff --git a/pypy/module/_io/test/test_stringio.py 
b/pypy/module/_io/test/test_stringio.py
--- a/pypy/module/_io/test/test_stringio.py
+++ b/pypy/module/_io/test/test_stringio.py
@@ -259,6 +259,8 @@
             assert line == s
             i += 1
         assert i == 10
+        sio.seek(len(s) * 10 +1)
+        assert list(sio) == []
         sio = io.StringIO(s * 2)
         sio.close()
         raises(ValueError, next, sio)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to