]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-140979: Fix off-by-one error in the RE code validator (GH-140984) (GH-141000)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 4 Nov 2025 16:16:40 +0000 (17:16 +0100)
committerGitHub <noreply@github.com>
Tue, 4 Nov 2025 16:16:40 +0000 (18:16 +0200)
It was too lenient and allowed MARK opcodes with too large value.
(cherry picked from commit 1326d2a808245e5f2de9e515460bab30556e8f05)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Modules/_sre/sre.c

index 898ebbfe89bcd231d6681f4ce447ab44612f8f3b..c0cc8268d2de507218e5f9a952473d4e09310c81 100644 (file)
@@ -1932,7 +1932,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;
             }