Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7bc4430

Browse files
committed
merge 3.5 (closes #27758)
2 parents c00189e + 9745ee0 commit 7bc4430

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ Library
5858

5959
- Issue #27661: Added tzinfo keyword argument to datetime.combine.
6060

61+
- Issue #27758: Fix possible integer overflow in the _csv module for large record
62+
lengths.
63+
6164
- Issue #27568: Prevent HTTPoxy attack (CVE-2016-1000110). Ignore the
6265
HTTP_PROXY variable when REQUEST_METHOD environment is set, which indicates
6366
that the script is in CGI mode.

Modules/_csv.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,11 +1014,19 @@ join_append_data(WriterObj *self, unsigned int field_kind, void *field_data,
10141014
int i;
10151015
Py_ssize_t rec_len;
10161016

1017-
#define ADDCH(c) \
1017+
#define INCLEN \
1018+
do {\
1019+
if (!copy_phase && rec_len == PY_SSIZE_T_MAX) { \
1020+
goto overflow; \
1021+
} \
1022+
rec_len++; \
1023+
} while(0)
1024+
1025+
#define ADDCH(c) \
10181026
do {\
10191027
if (copy_phase) \
10201028
self->rec[rec_len] = c;\
1021-
rec_len++;\
1029+
INCLEN;\
10221030
} while(0)
10231031

10241032
rec_len = self->rec_len;
@@ -1072,11 +1080,18 @@ join_append_data(WriterObj *self, unsigned int field_kind, void *field_data,
10721080
if (*quoted) {
10731081
if (copy_phase)
10741082
ADDCH(dialect->quotechar);
1075-
else
1076-
rec_len += 2;
1083+
else {
1084+
INCLEN; /* starting quote */
1085+
INCLEN; /* ending quote */
1086+
}
10771087
}
10781088
return rec_len;
1089+
1090+
overflow:
1091+
PyErr_NoMemory();
1092+
return -1;
10791093
#undef ADDCH
1094+
#undef INCLEN
10801095
}
10811096

10821097
static int

0 commit comments

Comments
 (0)