diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-11-20 21:30:42 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-11-20 21:30:42 (GMT) |
commit | b83ea144ccf39e2c9346d3a53cf67e154d29b4cb (patch) | |
tree | dcfd2b0d27c9c07254ed4449d4be6605e55586ea /Modules/_sre.c | |
parent | e78f12f7c29d0ac48b5fee86b9afb38012a809e5 (diff) | |
download | cpython-b83ea144ccf39e2c9346d3a53cf67e154d29b4cb.zip cpython-b83ea144ccf39e2c9346d3a53cf67e154d29b4cb.tar.gz cpython-b83ea144ccf39e2c9346d3a53cf67e154d29b4cb.tar.bz2 |
Issue #1160: Fix compiling large regular expressions on UCS2 builds.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r-- | Modules/_sre.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c index cd95917..ab4f269 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -2675,6 +2675,13 @@ _compile(PyObject* self_, PyObject* args) 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 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups) 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 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups) 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; |