Mercurial > cpython-lru_cache-weakref
diff Python/getargs.c @ 68794:d9633064458c 3.1
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 | Mon, 21 Mar 2011 03:22:50 +0100 |
| parents | 13b2a592c186 |
| children | 18f7fe1d2108 |
line wrap: on
line diff
--- a/Python/getargs.c Mon Mar 21 00:01:23 2011 +0100 +++ b/Python/getargs.c Mon Mar 21 03:22:50 2011 +0100 @@ -613,7 +613,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;
