10000 [3.11] gh-110590: Fix a bug where _sre.compile would overwrite exceptions (GH-110591) by miss-islington · Pull Request #110614 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.11] gh-110590: Fix a bug where _sre.compile would overwrite exceptions (GH-110591) #110614

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

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
gh-110590: Fix a bug where _sre.compile would overwrite exceptions (G…
…H-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>
  • Loading branch information
sobolevn authored and miss-islington committed Oct 10, 2023
commit 530247b7734659e6f97ba8235950e2084b76074c
3 changes: 3 additions & 0 deletions Lib/test/test_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,9 @@ def test_dealloc(self):
_sre.compile("abc", 0, [long_overflow], 0, {}, ())
with self.assertRaises(TypeError):
_sre.compile({}, 0, [], 0, [], [])
# gh-110590: `TypeError` was overwritten with `OverflowError`:
with self.assertRaises(TypeError):
_sre.compile('', 0, ['abc'], 0, {}, ())

@cpython_only
def test_repeat_minmax_overflow_maxrepeat(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a bug in :meth:`!_sre.compile` where :exc:`TypeError`
would be overwritten by :exc:`OverflowError` when
the *code* argument was a list of non-ints.
3 changes: 3 additions & 0 deletions Modules/_sre/sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,9 @@ _sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
for (i = 0; i < n; i++) {
PyObject *o = PyList_GET_ITEM(code, i);
unsigned long value = PyLong_AsUnsignedLong(o);
if (value == (unsigned long)-1 && PyErr_Occurred()) {
break;
}
self->code[i] = (SRE_CODE) value;
if ((unsigned long) self->code[i] != value) {
PyErr_SetString(PyExc_OverflowError,
Expand Down
0