summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-01-04 02:07:34 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-01-04 02:07:34 (GMT)
commitb3c9e073fc7b93529ceb0af520d148385e6f63f7 (patch)
tree77b8ef468c87c3258cd734fc2c438f57a71d0d65 /Python
parente6edec23718072ed7903be9dae37ae330a9d81d5 (diff)
downloadcpython-b3c9e073fc7b93529ceb0af520d148385e6f63f7.zip
cpython-b3c9e073fc7b93529ceb0af520d148385e6f63f7.tar.gz
cpython-b3c9e073fc7b93529ceb0af520d148385e6f63f7.tar.bz2
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).
Diffstat (limited to 'Python')
-rw-r--r--Python/getargs.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index cf98699..aac1d17 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -597,7 +597,17 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
#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;