From aead53b6ee27915de248b07de509529174aaad21 Mon Sep 17 00:00:00 2001 From: Johan Liu Date: Fri, 2 Jun 2017 14:33:04 +0800 Subject: bpo-30245: Fix possible overflow when organize struct.pack_into error message (#1682) --- Lib/test/test_struct.py | 10 ++++++++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ Modules/_struct.c | 7 +++++-- 4 files changed, 19 insertions(+), 2 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('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); -- cgit v0.12