From c829171625ba58e775f3d155da86382bbd36016d Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 10 Oct 2023 10:47:19 +0300 Subject: [PATCH 1/5] gh-110590: Fix `_sre.compile` error overwrite --- Lib/test/test_re.py | 3 +++ .../Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst | 2 ++ Modules/_sre/sre.c | 3 +++ 3 files changed, 8 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 45bce1925f9e89..301d4a516568b2 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -2735,6 +2735,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): diff --git a/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst b/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst new file mode 100644 index 00000000000000..a2b4074da65ac1 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst @@ -0,0 +1,2 @@ +Fix ``_sre.compile`` error overwriting `TypeError` with `OverflowError` when +`code` arguments was a list of non-ints. diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c index 07da5da13f70d3..798732ccddc99a 100644 --- a/Modules/_sre/sre.c +++ b/Modules/_sre/sre.c @@ -1508,6 +1508,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, From 18cd5edc3b1fa8d82717c6d3d6f2d6c74f83630a Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Tue, 10 Oct 2023 10:53:44 +0300 Subject: [PATCH 2/5] Update 2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst --- .../next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst b/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst index a2b4074da65ac1..b929a3f6a3f527 100644 --- a/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst +++ b/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst @@ -1,2 +1,2 @@ Fix ``_sre.compile`` error overwriting `TypeError` with `OverflowError` when -`code` arguments was a list of non-ints. +``code`` arguments was a list of non-ints. From dc22745bc89c5fc8075cb212d120a39cba509da1 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Tue, 10 Oct 2023 10:59:47 +0300 Subject: [PATCH 3/5] Update 2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst --- .../Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst b/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst index b929a3f6a3f527..df3e10a67552da 100644 --- a/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst +++ b/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst @@ -1,2 +1,3 @@ -Fix ``_sre.compile`` error overwriting `TypeError` with `OverflowError` when -``code`` arguments was a list of non-ints. +Fix ``_sre.compile`` error overwriting ``TypeError`` +with ``OverflowError`` when ``code`` arguments +was a list of non-ints. From 858fa3f58d57270161af5155d062e2ff030e5734 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Tue, 10 Oct 2023 11:09:42 +0300 Subject: [PATCH 4/5] Update 2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst --- .../next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst b/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst index df3e10a67552da..6c11644b811001 100644 --- a/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst +++ b/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst @@ -1,3 +1,3 @@ Fix ``_sre.compile`` error overwriting ``TypeError`` -with ``OverflowError`` when ``code`` arguments +with ``OverflowError`` when ``code`` argument was a list of non-ints. From cfb142e211d1b9fc0cd9c872788b3612efd94ad3 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 10 Oct 2023 11:30:27 +0200 Subject: [PATCH 5/5] Update Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst --- .../Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst b/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst index 6c11644b811001..20dc3fff205994 100644 --- a/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst +++ b/Misc/NEWS.d/next/Library/2023-10-10-10-46-55.gh-issue-110590.fatz-h.rst @@ -1,3 +1,3 @@ -Fix ``_sre.compile`` error overwriting ``TypeError`` -with ``OverflowError`` when ``code`` argument -was a list of non-ints. +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.