Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r89430:f2d9207e657b
Date: 2017-01-08 21:21 +0100
http://bitbucket.org/pypy/pypy/changeset/f2d9207e657b/
Log: Fix a division by zero
diff --git a/pypy/module/struct/interp_struct.py
b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -107,6 +107,10 @@
class W_UnpackIter(W_Root):
def __init__(self, space, w_struct, w_buffer):
buf = space.buffer_w(w_buffer, space.BUF_SIMPLE)
+ if w_struct.size <= 0:
+ raise oefmt(get_error(space),
+ "cannot iteratively unpack with a struct of length %d",
+ w_struct.size)
if buf.getlength() % w_struct.size != 0:
raise oefmt(get_error(space),
"iterative unpacking requires a bytes length multiple of %d",
diff --git a/pypy/module/struct/test/test_struct.py
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -423,6 +423,12 @@
raises(struct.error, s.iter_unpack, b'123')
raises(struct.error, struct.iter_unpack, 'h', b'12345')
+ def test_iter_unpack_empty_struct(self):
+ struct = self.struct
+ s = struct.Struct('')
+ raises(struct.error, s.iter_unpack, b'')
+ raises(struct.error, s.iter_unpack, b'?')
+
def test___float__(self):
class MyFloat(object):
def __init__(self, x):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit