Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_sre.compile overwrites TypeError with OverflowError #110590

Closed
sobolevn opened this issue Oct 10, 2023 · 0 comments
Closed

_sre.compile overwrites TypeError with OverflowError #110590

sobolevn opened this issue Oct 10, 2023 · 0 comments
Assignees
Labels
extension-modules C modules in the Modules dir topic-regex type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Oct 10, 2023

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

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error extension-modules C modules in the Modules dir labels Oct 10, 2023
@sobolevn sobolevn self-assigned this Oct 10, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Oct 10, 2023
erlend-aasland pushed a commit that referenced this issue Oct 10, 2023
…110591)

TypeError would be overwritten by OverflowError
if 'code' param contained non-ints.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 10, 2023
…ons (pythonGH-110591)

TypeError would be overwritten by OverflowError
if 'code' param contained non-ints.
(cherry picked from commit 344d3a2)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 10, 2023
…ons (pythonGH-110591)

TypeError would be overwritten by OverflowError
if 'code' param contained non-ints.
(cherry picked from commit 344d3a2)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
erlend-aasland pushed a commit that referenced this issue Oct 10, 2023
…ions (GH-110591) (#110614)

TypeError would be overwritten by OverflowError
if 'code' param contained non-ints.
(cherry picked from commit 344d3a2)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
erlend-aasland pushed a commit that referenced this issue Oct 10, 2023
…ions (GH-110591) (#110613)

TypeError would be overwritten by OverflowError
if 'code' param contained non-ints.
(cherry picked from commit 344d3a2)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir topic-regex type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants