changeset: 102639:55e8d3e542bd branch: 3.5 parent: 102633:c1cc1f616285 parent: 102638:10b89df93c58 user: Benjamin Peterson date: Sat Aug 13 17:21:54 2016 -0700 files: Misc/NEWS Modules/_csv.c description: merge 3.4 (closes #27758) diff -r c1cc1f616285 -r 55e8d3e542bd Misc/NEWS --- a/Misc/NEWS Sat Aug 13 14:47:18 2016 -0400 +++ b/Misc/NEWS Sat Aug 13 17:21:54 2016 -0700 @@ -37,6 +37,9 @@ - Issue #26750: unittest.mock.create_autospec() now works properly for subclasses of property() and other data descriptors. +- Issue #27758: Fix possible integer overflow in the _csv module for large record + lengths. + - Issue #27568: Prevent HTTPoxy attack (CVE-2016-1000110). Ignore the HTTP_PROXY variable when REQUEST_METHOD environment is set, which indicates that the script is in CGI mode. diff -r c1cc1f616285 -r 55e8d3e542bd Modules/_csv.c --- a/Modules/_csv.c Sat Aug 13 14:47:18 2016 -0400 +++ b/Modules/_csv.c Sat Aug 13 17:21:54 2016 -0700 @@ -1014,11 +1014,19 @@ int i; Py_ssize_t rec_len; -#define ADDCH(c) \ +#define INCLEN \ + do {\ + if (!copy_phase && rec_len == PY_SSIZE_T_MAX) { \ + goto overflow; \ + } \ + rec_len++; \ + } while(0) + +#define ADDCH(c) \ do {\ if (copy_phase) \ self->rec[rec_len] = c;\ - rec_len++;\ + INCLEN;\ } while(0) rec_len = self->rec_len; @@ -1072,11 +1080,18 @@ if (*quoted) { if (copy_phase) ADDCH(dialect->quotechar); - else - rec_len += 2; + else { + INCLEN; /* starting quote */ + INCLEN; /* ending quote */ + } } return rec_len; + + overflow: + PyErr_NoMemory(); + return -1; #undef ADDCH +#undef INCLEN } static int