]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-140979: Fix off-by-one error in the RE code validator (GH-140984)
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 4 Nov 2025 15:49:44 +0000 (17:49 +0200)
committerGitHub <noreply@github.com>
Tue, 4 Nov 2025 15:49:44 +0000 (17:49 +0200)
It was too lenient and allowed MARK opcodes with too large value.

Modules/_sre/sre.c

index fdf00e6499cb6bd365f5097840abc870ad1c409e..4e97101b699876fc9a209769a6d7a4499b3220e8 100644 (file)
@@ -1946,7 +1946,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
                sre_match() code is robust even if they don't, and the worst
                you can get is nonsensical match results. */
             GET_ARG;
-            if (arg > 2 * (size_t)groups + 1) {
+            if (arg >= 2 * (size_t)groups) {
                 VTRACE(("arg=%d, groups=%d\n", (int)arg, (int)groups));
                 FAIL;
             }