Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r94425:bae7d61d060c
Date: 2018-04-23 14:38 +0200
http://bitbucket.org/pypy/pypy/changeset/bae7d61d060c/

Log:    Fix a case where the list strategy leaks to the user

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -991,6 +991,14 @@
 
     def setslice(self, w_list, start, step, slicelength, w_other):
         strategy = w_other.strategy
+        if step != 1:
+            len2 = strategy.length(w_other)
+            if len2 == 0:
+                return
+            else:
+                raise oefmt(self.space.w_ValueError,
+                            "attempt to assign sequence of size %d to extended 
"
+                            "slice of size %d", len2, 0)
         storage = strategy.getstorage_copy(w_other)
         w_list.strategy = strategy
         w_list.lstorage = storage
diff --git a/pypy/objspace/std/test/test_listobject.py 
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -1080,6 +1080,15 @@
         l[::3] = ('a', 'b')
         assert l == ['a', 1.1, 2.2, 'b', 4.4, 5.5]
 
+        l_int = [5]; l_int.pop()   # IntListStrategy
+        l_empty = []               # EmptyListStrategy
+        raises(ValueError, "l_int[::-1] = [42]")
+        raises(ValueError, "l_int[::7] = [42]")
+        raises(ValueError, "l_empty[::-1] = [42]")
+        raises(ValueError, "l_empty[::7] = [42]")
+        l_int[::1] = [42]; assert l_int == [42]
+        l_empty[::1] = [42]; assert l_empty == [42]
+
     def test_setslice_with_self(self):
         l = [1,2,3,4]
         l[:] = l
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to