diff -r cd87afe18ff8 Lib/sre_constants.py --- a/Lib/sre_constants.py Wed Jan 23 08:38:47 2013 -0500 +++ b/Lib/sre_constants.py Wed Jan 23 22:12:34 2013 +0200 @@ -17,7 +17,7 @@ # max code word in this release -MAXREPEAT = 65535 +MAXREPEAT = 0xFFFFFFFF # SRE standard exception (access as sre.error) # should this really be here? @@ -219,8 +219,7 @@ if __name__ == "__main__": def dump(f, d, prefix): - items = d.items() - items.sort(key=lambda a: a[1]) + items = sorted(d.items(), key=lambda a: a[1]) for k, v in items: f.write("#define %s_%s %s\n" % (prefix, k.upper(), v)) f = open("sre_constants.h", "w") @@ -241,6 +240,7 @@ """) f.write("#define SRE_MAGIC %d\n" % MAGIC) + f.write("#define SRE_MAXREPEAT %dlu\n" % MAXREPEAT) dump(f, OPCODES, "SRE_OP") dump(f, ATCODES, "SRE") diff -r cd87afe18ff8 Lib/sre_parse.py --- a/Lib/sre_parse.py Wed Jan 23 08:38:47 2013 -0500 +++ b/Lib/sre_parse.py Wed Jan 23 22:12:34 2013 +0200 @@ -537,8 +537,12 @@ continue if lo: min = int(lo) + if min >= MAXREPEAT: + raise error("too large repeat number") if hi: max = int(hi) + if max >= MAXREPEAT: + raise error("too large repeat number") if max < min: raise error("bad repeat interval") else: diff -r cd87afe18ff8 Modules/_sre.c --- a/Modules/_sre.c Wed Jan 23 08:38:47 2013 -0500 +++ b/Modules/_sre.c Wed Jan 23 22:12:34 2013 +0200 @@ -492,7 +492,7 @@ 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 @@ } 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 @@ } 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 @@ 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 @@ 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 @@ 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; diff -r cd87afe18ff8 Modules/sre_constants.h --- a/Modules/sre_constants.h Wed Jan 23 08:38:47 2013 -0500 +++ b/Modules/sre_constants.h Wed Jan 23 22:12:34 2013 +0200 @@ -12,6 +12,7 @@ */ #define SRE_MAGIC 20031017 +#define SRE_MAXREPEAT 4294967295lu #define SRE_OP_FAILURE 0 #define SRE_OP_SUCCESS 1 #define SRE_OP_ANY 2