[3.13] gh-140979: Fix off-by-one error in the RE code validator (GH-140984) (GH-141000)

It was too lenient and allowed MARK opcodes with too large value.
(cherry picked from commit 1326d2a808)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-11-04 17:16:40 +01:00 committed by GitHub
parent 551d68d8cf
commit fd9be78f4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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;
}