]> granicus.if.org Git - python/commitdiff
Issue #5308: Raise ValueError when marshalling too large object (a sequence
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 13 Feb 2013 10:11:03 +0000 (12:11 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 13 Feb 2013 10:11:03 +0000 (12:11 +0200)
with size >= 2**31), instead of producing illegal marshal data.

1  2 
Lib/test/test_marshal.py
Misc/NEWS
Python/marshal.c

Simple merge
diff --cc Misc/NEWS
Simple merge
index 6d52a840ce354bc923ec0e81bdfd24d2619da40b,1edb696fd970f687ef1d2b22f59ed0a596966259..959f3f7f2cd50a028ddb31467faf188a91f879a7
@@@ -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)) {