summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_struct.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-04-20 18:19:31 (GMT)
committerGitHub <noreply@github.com>2017-04-20 18:19:31 (GMT)
commit40db90c1ce1a59d5f5f2894bb0ce32110000bf27 (patch)
tree0436658cf04e8ebd902a9bc1851b21ee7b98bf45 /Lib/test/test_struct.py
parent8f5cdfa9fc1bb6b4d9a33fc281987252f6398430 (diff)
downloadcpython-40db90c1ce1a59d5f5f2894bb0ce32110000bf27.zip
cpython-40db90c1ce1a59d5f5f2894bb0ce32110000bf27.tar.gz
cpython-40db90c1ce1a59d5f5f2894bb0ce32110000bf27.tar.bz2
bpo-29802: Fix reference counting in module-level struct functions (#1213)
when pass arguments of wrong type.
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r--Lib/test/test_struct.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 932ef47..02d50b2 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -599,6 +599,16 @@ class StructTest(unittest.TestCase):
'offset -11 out of range for 10-byte buffer'):
struct.pack_into('<B', byte_list, -11, 123)
+ def test_issue29802(self):
+ # When the second argument of struct.unpack() was of wrong type
+ # the Struct object was decrefed twice and the reference to
+ # deallocated object was left in a cache.
+ with self.assertRaises(TypeError):
+ struct.unpack(b'b', 0)
+ # Shouldn't crash.
+ self.assertEqual(struct.unpack(b'b', b'a'), (b'a'[0],))
+
+
class UnpackIteratorTest(unittest.TestCase):
"""
Tests for iterative unpacking (struct.Struct.iter_unpack).