diff Python/getargs.c @ 69799:a0681e7a6ded 2.7

Issue #8651: PyArg_Parse*() functions raise an OverflowError if the file doesn't have PY_SSIZE_T_CLEAN define and the size doesn't fit in an int (length bigger than 2^31-1 bytes).
author Victor Stinner <victor.stinner@haypocalc.com>
date Tue, 03 May 2011 15:09:24 +0200
parents 509f1c15a1e1
children 17c671529f7e
line wrap: on
line diff
--- a/Python/getargs.c	Tue May 03 15:06:11 2011 +0200
+++ b/Python/getargs.c	Tue May 03 15:09:24 2011 +0200
@@ -585,7 +585,17 @@
 #define FETCH_SIZE      int *q=NULL;Py_ssize_t *q2=NULL;\
     if (flags & FLAG_SIZE_T) q2=va_arg(*p_va, Py_ssize_t*); \
     else q=va_arg(*p_va, int*);
-#define STORE_SIZE(s)   if (flags & FLAG_SIZE_T) *q2=s; else *q=s;
+#define STORE_SIZE(s)   \
+    if (flags & FLAG_SIZE_T) \
+        *q2=s; \
+    else { \
+        if (INT_MAX < s) { \
+            PyErr_SetString(PyExc_OverflowError, \
+                "size does not fit in an int"); \
+            return converterr("", arg, msgbuf, bufsize); \
+        } \
+        *q=s; \
+    }
 #define BUFFER_LEN      ((flags & FLAG_SIZE_T) ? *q2:*q)
 
     const char *format = *p_format;