From d888f161a45619cef02dd7c5fd57be420db40d01 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Wed, 19 Aug 2026 21:02:47 +0100 Subject: [PATCH 1/2] Fix two error handling issues in `_zoneinfo.load_data()` --- .../2026-08-19-21-01-19.gh-issue-156067.1CXkqc.rst | 2 ++ Modules/_zoneinfo.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-08-19-21-01-19.gh-issue-156067.1CXkqc.rst diff --git a/Misc/NEWS.d/next/Library/2026-08-19-21-01-19.gh-issue-156067.1CXkqc.rst b/Misc/NEWS.d/next/Library/2026-08-19-21-01-19.gh-issue-156067.1CXkqc.rst new file mode 100644 index 000000000000000..af4c778ece5d703 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-19-21-01-19.gh-issue-156067.1CXkqc.rst @@ -0,0 +1,2 @@ +Fix error handling in the :mod:`zoneinfo` accelerator module when a +transition index is ``-1`` or a TZ string's ``__bool__`` raises. diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 464e145438ae733..185ae93886a6ba1 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -1070,7 +1070,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj) } Py_ssize_t cur_trans_idx = PyLong_AsSsize_t(num); - if (cur_trans_idx == -1) { + if (cur_trans_idx == -1 && PyErr_Occurred()) { goto error; } @@ -1181,7 +1181,15 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj) self->ttinfo_before = &(self->_ttinfos[0]); } - if (tz_str != Py_None && PyObject_IsTrue(tz_str)) { + int has_tz_str = 0; + if (tz_str != Py_None) { + has_tz_str = PyObject_IsTrue(tz_str); + if (has_tz_str < 0) { + goto error; + } + } + + if (has_tz_str) { if (parse_tz_str(state, tz_str, &(self->tzrule_after))) { goto error; } From 86be86e4b10c7dae3b45ee6e75a4748c6f985a8d Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Wed, 19 Aug 2026 22:43:18 +0100 Subject: [PATCH 2/2] Simplify --- Modules/_zoneinfo.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 185ae93886a6ba1..56ccabbea0ab480 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -1181,12 +1181,9 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj) self->ttinfo_before = &(self->_ttinfos[0]); } - int has_tz_str = 0; - if (tz_str != Py_None) { - has_tz_str = PyObject_IsTrue(tz_str); - if (has_tz_str < 0) { - goto error; - } + int has_tz_str = PyObject_IsTrue(tz_str); + if (has_tz_str < 0) { + goto error; } if (has_tz_str) {