summaryrefslogtreecommitdiffstats
path: root/Modules/_struct.c
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 /Modules/_struct.c
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 'Modules/_struct.c')
-rw-r--r--Modules/_struct.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 8e1e219..5b74ec5 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1929,11 +1929,14 @@ s_pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames
/* Check boundaries */
if ((buffer.len - offset) < soself->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);