summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-02-16 14:55:54 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-02-16 14:55:54 (GMT)
commit165ee9645b6518f36c3ec23d0e64d2956e42c5c4 (patch)
tree30646ddd2223b92181f05b334089a8526a2e00fd /Modules
parent178e6fef9e8f6248dcc77022d0f448b33698ad8f (diff)
parenta0eb80999538febe046164bae541d3f07b899dfb (diff)
downloadcpython-165ee9645b6518f36c3ec23d0e64d2956e42c5c4.zip
cpython-165ee9645b6518f36c3ec23d0e64d2956e42c5c4.tar.gz
cpython-165ee9645b6518f36c3ec23d0e64d2956e42c5c4.tar.bz2
Issue #13169: The maximal repetition number in a regular expression has been
increased from 65534 to 2147483647 (on 32-bit platform) or 4294967294 (on 64-bit).
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_sre.c18
-rw-r--r--Modules/sre.h5
2 files changed, 17 insertions, 6 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 24eb4dd..f2d8a37 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -492,7 +492,7 @@ SRE_COUNT(SRE_STATE* state, SRE_CODE* pattern, Py_ssize_t maxcount)
Py_ssize_t i;
/* adjust end */
- if (maxcount < (end - ptr) / state->charsize && maxcount != 65535)
+ if (maxcount < (end - ptr) / state->charsize && maxcount != SRE_MAXREPEAT)
end = ptr + maxcount*state->charsize;
switch (pattern[0]) {
@@ -1109,7 +1109,7 @@ entrance:
} else {
/* general case */
LASTMARK_SAVE();
- while ((Py_ssize_t)ctx->pattern[2] == 65535
+ while ((Py_ssize_t)ctx->pattern[2] == SRE_MAXREPEAT
|| ctx->count <= (Py_ssize_t)ctx->pattern[2]) {
state->ptr = ctx->ptr;
DO_JUMP(JUMP_MIN_REPEAT_ONE,jump_min_repeat_one,
@@ -1195,7 +1195,7 @@ entrance:
}
if ((ctx->count < ctx->u.rep->pattern[2] ||
- ctx->u.rep->pattern[2] == 65535) &&
+ ctx->u.rep->pattern[2] == SRE_MAXREPEAT) &&
state->ptr != ctx->u.rep->last_ptr) {
/* we may have enough matches, but if we can
match another item, do so */
@@ -1273,7 +1273,7 @@ entrance:
LASTMARK_RESTORE();
if (ctx->count >= ctx->u.rep->pattern[2]
- && ctx->u.rep->pattern[2] != 65535)
+ && ctx->u.rep->pattern[2] != SRE_MAXREPEAT)
RETURN_FAILURE;
ctx->u.rep->count = ctx->count;
@@ -3037,7 +3037,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
GET_ARG; max = arg;
if (min > max)
FAIL;
- if (max > 65535)
+ if (max > SRE_MAXREPEAT)
FAIL;
if (!_validate_inner(code, code+skip-4, groups))
FAIL;
@@ -3056,7 +3056,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
GET_ARG; max = arg;
if (min > max)
FAIL;
- if (max > 65535)
+ if (max > SRE_MAXREPEAT)
FAIL;
if (!_validate_inner(code, code+skip-3, groups))
FAIL;
@@ -3942,6 +3942,12 @@ PyMODINIT_FUNC PyInit__sre(void)
Py_DECREF(x);
}
+ x = PyLong_FromUnsignedLong(SRE_MAXREPEAT);
+ if (x) {
+ PyDict_SetItemString(d, "MAXREPEAT", x);
+ Py_DECREF(x);
+ }
+
x = PyUnicode_FromString(copyright);
if (x) {
PyDict_SetItemString(d, "copyright", x);
diff --git a/Modules/sre.h b/Modules/sre.h
index 00b52aa..1a6cd56 100644
--- a/Modules/sre.h
+++ b/Modules/sre.h
@@ -16,6 +16,11 @@
/* size of a code word (must be unsigned short or larger, and
large enough to hold a UCS4 character) */
#define SRE_CODE Py_UCS4
+#if SIZEOF_SIZE_T > 4
+# define SRE_MAXREPEAT (~(SRE_CODE)0)
+#else
+# define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX + 1u)
+#endif
typedef struct {
PyObject_VAR_HEAD