Skip to content

Commit c829171

Browse files
committed
pythongh-110590: Fix _sre.compile error overwrite
1 parent def7ea5 commit c829171

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

Lib/test/test_re.py

+3
Original file line numberDiff line numberDiff line change
@@ -2735,6 +2735,9 @@ def test_dealloc(self):
27352735
_sre.compile("abc", 0, [long_overflow], 0, {}, ())
27362736
with self.assertRaises(TypeError):
27372737
_sre.compile({}, 0, [], 0, [], [])
2738+
# gh-110590: `TypeError` was overwritten with `OverflowError`:
2739+
with self.assertRaises(TypeError):
2740+
_sre.compile('', 0, ['abc'], 0, {}, ())
27382741

27392742
@cpython_only
27402743
def test_repeat_minmax_overflow_maxrepeat(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``_sre.compile`` error overwriting `TypeError` with `OverflowError` when
2+
`code` arguments was a list of non-ints.

Modules/_sre/sre.c

+3
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,9 @@ _sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
15081508
for (i = 0; i < n; i++) {
15091509
PyObject *o = PyList_GET_ITEM(code, i);
15101510
unsigned long value = PyLong_AsUnsignedLong(o);
1511+
if (value == (unsigned long)-1 && PyErr_Occurred()) {
1512+
break;
1513+
}
15111514
self->code[i] = (SRE_CODE) value;
15121515
if ((unsigned long) self->code[i] != value) {
15131516
PyErr_SetString(PyExc_OverflowError,

0 commit comments

Comments
 (0)