summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2016-08-14 00:21:54 (GMT)
committerBenjamin Peterson <benjamin@python.org>2016-08-14 00:21:54 (GMT)
commit9745ee0b444c92a23a1b8851f789044baa64dba5 (patch)
treef65b25581349d5f299e1dc776467f873247447a6
parent689016fc00a8cfe3dda3807a1ad01a513906b368 (diff)
parent59b6abd38c04472a256b1b04e8709defb29e44ef (diff)
downloadcpython-9745ee0b444c92a23a1b8851f789044baa64dba5.zip
cpython-9745ee0b444c92a23a1b8851f789044baa64dba5.tar.gz
cpython-9745ee0b444c92a23a1b8851f789044baa64dba5.tar.bz2
merge 3.4 (closes #27758)
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_csv.c23
2 files changed, 22 insertions, 4 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 5ee72c6..ed580d1 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,9 @@ Library
- 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 --git a/Modules/_csv.c b/Modules/_csv.c
index 101f449..b428279 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -1014,11 +1014,19 @@ join_append_data(WriterObj *self, unsigned int field_kind, void *field_data,
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 @@ join_append_data(WriterObj *self, unsigned int field_kind, void *field_data,
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