From: Serhiy Storchaka Date: Wed, 13 Feb 2013 10:11:03 +0000 (+0200) Subject: Issue #5308: Raise ValueError when marshalling too large object (a sequence X-Git-Tag: v3.3.1rc1~178 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5a1f152d198722aa4c36e65f952bc92e0f8ac747;p=python Issue #5308: Raise ValueError when marshalling too large object (a sequence with size >= 2**31), instead of producing illegal marshal data. --- 5a1f152d198722aa4c36e65f952bc92e0f8ac747 diff --cc Python/marshal.c index 6d52a840ce,1edb696fd9..959f3f7f2c --- a/Python/marshal.c +++ b/Python/marshal.c @@@ -124,6 -121,30 +124,21 @@@ w_long(long x, WFILE *p w_byte((char)((x>>24) & 0xff), p); } -#if SIZEOF_LONG > 4 -static void -w_long64(long x, WFILE *p) -{ - w_long(x, p); - w_long(x>>32, p); -} -#endif - + #define SIZE32_MAX 0x7FFFFFFF + + #if SIZEOF_SIZE_T > 4 + # define W_SIZE(n, p) do { \ + if ((n) > SIZE32_MAX) { \ + (p)->depth--; \ + (p)->error = WFERR_UNMARSHALLABLE; \ + return; \ + } \ + w_long((long)(n), p); \ + } while(0) + #else + # define W_SIZE w_long + #endif + /* We assume that Python longs are stored internally in base some power of 2**15; for the sake of portability we'll always read and write them in base exactly 2**15. */ @@@ -474,9 -489,7 +478,9 @@@ r_string(char *s, Py_ssize_t n, RFILE * } } else { - PyObject *data = PyObject_CallMethod(p->readable, "read", "n", n); + _Py_IDENTIFIER(read); + - PyObject *data = _PyObject_CallMethodId(p->readable, &PyId_read, "i", n); ++ PyObject *data = _PyObject_CallMethodId(p->readable, &PyId_read, "n", n); read = 0; if (data != NULL) { if (!PyBytes_Check(data)) {