Skip to content

Commit aac31ae

Browse files
StanFromIrelandmiss-islington
authored andcommitted
gh-156067: Fix two error handling issues in _zoneinfo.load_data() (GH-156068)
(cherry picked from commit 21a6a8a) Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 1547edc commit aac31ae

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
@@ -1067,7 +1067,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
10671067
}
10681068

10691069
Py_ssize_t cur_trans_idx = PyLong_AsSsize_t(num);
1070-
if (cur_trans_idx == -1) {
1070+
if (cur_trans_idx == -1 && PyErr_Occurred()) {
10711071
goto error;
10721072
}
10731073

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

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

0 commit comments

Comments
 (0)