check for overflow in join_append_data (closes #27758)
Reported by Thomas E. Hybel
diff --git a/Modules/_csv.c b/Modules/_csv.c
index af46658..4589f06 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -985,11 +985,19 @@
int i, rec_len;
char *lineterm;
-#define ADDCH(c) \
+#define INCLEN \
+ do {\
+ if (!copy_phase && rec_len == INT_MAX) { \
+ goto overflow; \
+ } \
+ rec_len++; \
+ } while(0)
+
+#define ADDCH(c) \
do {\
if (copy_phase) \
self->rec[rec_len] = c;\
- rec_len++;\
+ INCLEN;\
} while(0)
lineterm = PyString_AsString(dialect->lineterminator);
@@ -1059,11 +1067,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