Content-Length: 303744 | pFad | https://github.com/python/cpython/issues/110590

4B `_sre.compile` overwrites `TypeError` with `OverflowError` · Issue #110590 · python/cpython · GitHub
Skip to content

_sre.compile overwrites TypeError with OverflowError #110590

@sobolevn

Description

@sobolevn

Bug report

Reproduction:

>>> import _sre
>>> _sre.compile('', 0, ['abc'], 0, {}, ())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: regular expression code size limit exceeded

It should be:

>>> import _sre
>>> _sre.compile('', 0, ['abc'], 0, {}, ())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required

Because the third arg is code: object(subclass_of='&PyList_Type'), it is assumed to be integers inside.

Problematic lines:

cpython/Modules/_sre/sre.c

Lines 1510 to 1515 in def7ea5

unsigned long value = PyLong_AsUnsignedLong(o);
self->code[i] = (SRE_CODE) value;
if ((unsigned long) self->code[i] != value) {
PyErr_SetString(PyExc_OverflowError,
"regular expression code size limit exceeded");
break;

They do not check for PyLong_AsUnsignedLong errors.
I have a PR ready :)

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/110590

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy