summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-09-29 19:12:29 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-09-29 19:12:29 (GMT)
commit525faaeffc557899b83463f3b1b74d2f39cc7e13 (patch)
tree23d61a8eaf7970445f079e872539c062f1615cc1 /Modules
parent28d982dfc53eea290b898b30ab8feab8d7e55552 (diff)
parente060619d4b047fdee613cafc64e3a9242a68ea54 (diff)
downloadcpython-525faaeffc557899b83463f3b1b74d2f39cc7e13.zip
cpython-525faaeffc557899b83463f3b1b74d2f39cc7e13.tar.gz
cpython-525faaeffc557899b83463f3b1b74d2f39cc7e13.tar.bz2
Issue #25262. Added support for BINBYTES8 opcode in Python implementation of
unpickler. Highest 32 bits of 64-bit size for BINUNICODE8 and BINBYTES8 opcodes no longer silently ignored on 32-bit platforms in C implementation.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_pickle.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 123f14b..f3b73f1 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -4606,10 +4606,20 @@ static Py_ssize_t
calc_binsize(char *bytes, int nbytes)
{
unsigned char *s = (unsigned char *)bytes;
- Py_ssize_t i;
+ int i;
size_t x = 0;
- for (i = 0; i < nbytes && (size_t)i < sizeof(size_t); i++) {
+ if (nbytes > (int)sizeof(size_t)) {
+ /* Check for integer overflow. BINBYTES8 and BINUNICODE8 opcodes
+ * have 64-bit size that can't be represented on 32-bit platform.
+ */
+ for (i = (int)sizeof(size_t); i < nbytes; i++) {
+ if (s[i])
+ return -1;
+ }
+ nbytes = (int)sizeof(size_t);
+ }
+ for (i = 0; i < nbytes; i++) {
x |= (size_t) s[i] << (8 * i);
}