mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
bpo-30245: Fix possible overflow when organize struct.pack_into error message (#1682)
This commit is contained in:
parent
cdb89cd72c
commit
aead53b6ee
4 changed files with 19 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue