From: Johan Liu Date: Fri, 2 Jun 2017 06:33:04 +0000 (+0800) Subject: bpo-30245: Fix possible overflow when organize struct.pack_into error message (#1682) X-Git-Tag: v3.7.0a1~701 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aead53b6ee27915de248b07de509529174aaad21;p=thirdparty%2FPython%2Fcpython.git bpo-30245: Fix possible overflow when organize struct.pack_into error message (#1682) --- diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 02d50b2d1c37..b2a5f429e0b9 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('s_size) { + assert(offset >= 0); + assert(soself->s_size >= 0); + PyErr_Format(StructError, - "pack_into requires a buffer of at least %zd bytes for " + "pack_into requires a buffer of at least %zu bytes for " "packing %zd bytes at offset %zd " "(actual buffer size is %zd)", - soself->s_size + offset, + (size_t)soself->s_size + (size_t)offset, soself->s_size, offset, buffer.len);