Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix 30245
  • Loading branch information
johanliu committed May 20, 2017
commit c876f9a66356b5b5c60fc63e80e87ddc35b4d0ec
21 changes: 11 additions & 10 deletions Lib/test/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,16 +444,6 @@ def test_pack_into(self):
self.assertRaises((TypeError, struct.error), struct.pack_into, b'', sb,
None)

# Test overflows cause by large offset and value size (issue 30245)
regex = (
"pack_into requires a buffer of at least " + str(sys.maxsize + 4) +
" bytes for packing 4 bytes at offset " + str(sys.maxsize) +
" (actual buffer size is 10)"
)

with self.assertRaisesRegex(struct.error, regex):
struct.pack_into('I', bytearray(10), sys.maxsize, 1)

def test_pack_into_fn(self):
test_string = b'Reykjavik rocks, eow!'
writable_buf = array.array('b', b' '*100)
Expand Down Expand Up @@ -609,6 +599,17 @@ def test_boundary_error_message_with_negative_offset(self):
'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 = (
"pack_into requires a buffer of at least " + str(sys.maxsize + 4) +
" bytes for packing 4 bytes at offset " + str(sys.maxsize) +
" \(actual buffer size is 10\)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use raw string literals. Compiling "\(" emits a deprecation warning.

You also could use classic string formatting, string's format() method, or f-string expression for composing this string.

)

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
Expand Down