Skip to content

Commit 21a6a8a

Browse files
gh-156067: Fix two error handling issues in _zoneinfo.load_data() (#156068)
1 parent 7f6389f commit 21a6a8a

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
@@ -1070,7 +1070,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
10701070
}
10711071

10721072
Py_ssize_t cur_trans_idx = PyLong_AsSsize_t(num);
1073-
if (cur_trans_idx == -1) {
1073+
if (cur_trans_idx == -1 && PyErr_Occurred()) {
10741074
goto error;
10751075
}
10761076

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

1184-
if (tz_str != Py_None && PyObject_IsTrue(tz_str)) {
1184+
int has_tz_str = PyObject_IsTrue(tz_str);
1185+
if (has_tz_str < 0) {
1186+
goto error;
1187+
}
1188+
1189+
if (has_tz_str) {
11851190
if (parse_tz_str(state, tz_str, &(self->tzrule_after))) {
11861191
goto error;
11871192
}

0 commit comments

Comments
 (0)