diff -r f6c4c178da56 Modules/_sre.c --- a/Modules/_sre.c Sun Nov 11 14:01:23 2012 +0100 +++ b/Modules/_sre.c Sun Nov 11 20:39:15 2012 +0200 @@ -2675,6 +2675,13 @@ PyObject *o = PyList_GET_ITEM(code, i); unsigned long value = PyInt_Check(o) ? (unsigned long)PyInt_AsLong(o) : PyLong_AsUnsignedLong(o); + if (value == (unsigned long)-1 && PyErr_Occurred()) { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) { + PyErr_SetString(PyExc_OverflowError, + "regular expression code size limit exceeded"); + } + break; + } self->code[i] = (SRE_CODE) value; if ((unsigned long) self->code[i] != value) { PyErr_SetString(PyExc_OverflowError, @@ -3035,10 +3042,8 @@ GET_ARG; max = arg; if (min > max) FAIL; -#ifdef Py_UNICODE_WIDE if (max > 65535) FAIL; -#endif if (!_validate_inner(code, code+skip-4, groups)) FAIL; code += skip-4; @@ -3056,10 +3061,8 @@ GET_ARG; max = arg; if (min > max) FAIL; -#ifdef Py_UNICODE_WIDE if (max > 65535) FAIL; -#endif if (!_validate_inner(code, code+skip-3, groups)) FAIL; code += skip-3; diff -r f6c4c178da56 Modules/sre.h --- a/Modules/sre.h Sun Nov 11 14:01:23 2012 +0100 +++ b/Modules/sre.h Sun Nov 11 20:39:15 2012 +0200 @@ -14,12 +14,8 @@ #include "sre_constants.h" /* size of a code word (must be unsigned short or larger, and - large enough to hold a Py_UNICODE character) */ -#ifdef Py_UNICODE_WIDE + large enough to hold a UCS4 character) */ #define SRE_CODE Py_UCS4 -#else -#define SRE_CODE unsigned short -#endif typedef struct { PyObject_VAR_HEAD