Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
6. validate in _validate_inner()
  • Loading branch information
wjssz committed Apr 1, 2022
commit 6ec932b3fdd294345dc8df662e8d38676d7b45fe
18 changes: 13 additions & 5 deletions Modules/_sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -1471,9 +1471,8 @@ _sre_compile_impl(PyObject *module, PyObject *pattern, int flags,

Py_INCREF(pattern);
self->pattern = pattern;

self->repeat_count = repeat_count;
self->flags = flags;

self->groups = groups;

if (PyDict_GET_SIZE(groupindex) > 0) {
Expand Down Expand Up @@ -1838,17 +1837,25 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, PatternObject *self)
case SRE_OP_REPEAT:
case SRE_OP_POSSESSIVE_REPEAT:
{
SRE_CODE op1 = op, min, max;
SRE_CODE op1 = op, min, max, repeat_index, _fields;
GET_SKIP;
GET_ARG; min = arg;
GET_ARG; max = arg;
if (min > max)
FAIL;
if (max > SRE_MAXREPEAT)
FAIL;
if (!_validate_inner(code, code+skip-3, self))
if (op1 != SRE_OP_POSSESSIVE_REPEAT) {
GET_ARG; repeat_index = arg;
if (repeat_index >= (size_t)self->repeat_count)
FAIL;
_fields = 4;
} else {
_fields = 3;
}
if (!_validate_inner(code, code+skip-_fields, self))
FAIL;
code += skip-3;
code += skip-_fields;
GET_OP;
if (op1 == SRE_OP_POSSESSIVE_REPEAT) {
if (op != SRE_OP_SUCCESS)
Expand Down Expand Up @@ -1966,6 +1973,7 @@ static int
_validate_outer(SRE_CODE *code, SRE_CODE *end, PatternObject *self)
{
if (self->groups < 0 || (size_t)self->groups > SRE_MAXGROUPS ||
self->repeat_count < 0 ||
code >= end || end[-1] != SRE_OP_SUCCESS)
FAIL;
return _validate_inner(code, end-1, self);
Expand Down