diff options
author | Benjamin Peterson <benjamin@python.org> | 2016-08-14 01:37:12 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2016-08-14 01:37:12 (GMT) |
commit | 91060f26f960ceb2ba9da5f86585836e7c2a8b2d (patch) | |
tree | bf3c11c30b927965265fc3162bff79f786024853 /Modules/binascii.c | |
parent | f17a8e9acd6f4b9056f412595ffdbaf8e4c5b7ec (diff) | |
parent | 5295532adb9d33970dd0f3370ab45c4e3bc3757c (diff) | |
download | cpython-91060f26f960ceb2ba9da5f86585836e7c2a8b2d.zip cpython-91060f26f960ceb2ba9da5f86585836e7c2a8b2d.tar.gz cpython-91060f26f960ceb2ba9da5f86585836e7c2a8b2d.tar.bz2 |
merge 3.4 (closes #27760)
Diffstat (limited to 'Modules/binascii.c')
-rw-r--r-- | Modules/binascii.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c index 13780b2..f0b47d8 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -1383,6 +1383,7 @@ binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs, /* First, scan to see how many characters need to be encoded */ in = 0; while (in < datalen) { + Py_ssize_t delta = 0; if ((databuf[in] > 126) || (databuf[in] == '=') || (header && databuf[in] == '_') || @@ -1397,12 +1398,12 @@ binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs, if ((linelen + 3) >= MAXLINESIZE) { linelen = 0; if (crlf) - odatalen += 3; + delta += 3; else - odatalen += 2; + delta += 2; } linelen += 3; - odatalen += 3; + delta += 3; in++; } else { @@ -1414,11 +1415,11 @@ binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs, linelen = 0; /* Protect against whitespace on end of line */ if (in && ((databuf[in-1] == ' ') || (databuf[in-1] == '\t'))) - odatalen += 2; + delta += 2; if (crlf) - odatalen += 2; + delta += 2; else - odatalen += 1; + delta += 1; if (databuf[in] == '\r') in += 2; else @@ -1430,15 +1431,20 @@ binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs, (linelen + 1) >= MAXLINESIZE) { linelen = 0; if (crlf) - odatalen += 3; + delta += 3; else - odatalen += 2; + delta += 2; } linelen++; - odatalen++; + delta++; in++; } } + if (PY_SSIZE_T_MAX - delta < odatalen) { + PyErr_NoMemory(); + return NULL; + } + odatalen += delta; } /* We allocate the output same size as input, this is overkill. |