[3.14] gh-156067: Fix two error handling issues in `_zoneinfo.load_data()` (GH-156068) (#156089)

StanFromIreland <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/2a68e5b8ad1118264077248ab1bce94d66ca1945
commit: 2a68e5b8ad1118264077248ab1bce94d66ca1945
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-08-20T09:46:25Z
summary:

[3.14] gh-156067: Fix two error handling issues in `_zoneinfo.load_data()` (GH-156068) (#156089)

(cherry picked from commit 21a6a8a89246cb3c78d1e517084caf2d47c822f7)

Co-authored-by: Stan Ulbrych <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-08-19-21-01-19.gh-issue-156067.1CXkqc.rst
M Modules/_zoneinfo.c

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 00000000000000..af4c778ece5d70
--- /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 6aa604c18757ea..40b82ec029b185 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -1067,7 +1067,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;
         }
 
@@ -1178,7 +1178,12 @@ 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 = 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;
         }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.