Skip to content

Commit 200b98b

Browse files
[3.13] gh-156067: Fix two error handling issues in _zoneinfo.load_data() (GH-156068) (#156090)
(cherry picked from commit 21a6a8a) Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 962d769 commit 200b98b

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix error handling in the :mod:`zoneinfo` accelerator module when a
2+
transition index is ``-1`` or a TZ string's ``__bool__`` raises.

Modules/_zoneinfo.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
10681068
}
10691069

10701070
Py_ssize_t cur_trans_idx = PyLong_AsSsize_t(num);
1071-
if (cur_trans_idx == -1) {
1071+
if (cur_trans_idx == -1 && PyErr_Occurred()) {
10721072
goto error;
10731073
}
10741074

@@ -1179,7 +1179,12 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
11791179
self->ttinfo_before = &(self->_ttinfos[0]);
11801180
}
11811181

1182-
if (tz_str != Py_None && PyObject_IsTrue(tz_str)) {
1182+
int has_tz_str = PyObject_IsTrue(tz_str);
1183+
if (has_tz_str < 0) {
1184+
goto error;
1185+
}
1186+
1187+
if (has_tz_str) {
11831188
if (parse_tz_str(state, tz_str, &(self->tzrule_after))) {
11841189
goto error;
11851190
}

0 commit comments

Comments
 (0)