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

Skip to content

Commit 59b6abd

Browse files
committed
merge 3.3 (#27758)
2 parents a0b2568 + 6e01d90 commit 59b6abd

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
@@ -13,6 +13,9 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #27758: Fix possible integer overflow in the _csv module for large record
17+
lengths.
18+
1619
- Issue #27568: Prevent HTTPoxy attack (CVE-2016-1000110). Ignore the
1720
HTTP_PROXY variable when REQUEST_METHOD environment is set, which indicates
1821
that the script is in CGI mode.

Modules/_csv.c

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

1019-
#define ADDCH(c) \
1019+
#define INCLEN \
1020+
do {\
1021+
if (!copy_phase && rec_len == PY_SSIZE_T_MAX) { \
1022+
goto overflow; \
1023+
} \
1024+
rec_len++; \
1025+
} while(0)
1026+
1027+
#define ADDCH(c) \
10201028
do {\
10211029
if (copy_phase) \
10221030
self->rec[rec_len] = c;\
1023-
rec_len++;\
1031+
INCLEN;\
10241032
} while(0)
10251033

10261034
rec_len = self->rec_len;
@@ -1086,11 +1094,18 @@ join_append_data(WriterObj *self, unsigned int field_kind, void *field_data,
10861094
if (*quoted) {
10871095
if (copy_phase)
10881096
ADDCH(dialect->quotechar);
1089-
else
1090-
rec_len += 2;
1097+
else {
1098+
INCLEN; /* starting quote */
1099+
INCLEN; /* ending quote */
1100+
}
10911101
}
10921102
return rec_len;
1103+
1104+
overflow:
1105+
PyErr_NoMemory();
1106+
return -1;
10931107
#undef ADDCH
1108+
#undef INCLEN
10941109
}
10951110

10961111
static int

0 commit comments

Comments
 (0)