summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJohan Liu <akira.lau@hotmail.com>2017-06-02 06:33:04 (GMT)
committerXiang Zhang <angwerzx@126.com>2017-06-02 06:33:04 (GMT)
commitaead53b6ee27915de248b07de509529174aaad21 (patch)
tree5d0ab3d80216deccea25d93e17501b2f51184302 /Lib
parentcdb89cd72cbc66e4626914b4a71b9052ddb3a32a (diff)
downloadcpython-aead53b6ee27915de248b07de509529174aaad21.zip
cpython-aead53b6ee27915de248b07de509529174aaad21.tar.gz
cpython-aead53b6ee27915de248b07de509529174aaad21.tar.bz2
bpo-30245: Fix possible overflow when organize struct.pack_into error message (#1682)
Diffstat (limited to 'Lib')
-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 02d50b2..b2a5f42 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_boundary_error_message_with_large_offset(self):
+ # Test overflows cause by large offset and value size (issue 30245)
+ regex = (
+ r'pack_into requires a buffer of at least ' + str(sys.maxsize + 4) +
+ r' bytes for packing 4 bytes at offset ' + str(sys.maxsize) +
+ r' \(actual buffer size is 10\)'
+ )
+ with self.assertRaisesRegex(struct.error, regex):
+ struct.pack_into('<I', bytearray(10), sys.maxsize, 1)
+
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