Skip to content

Commit d888f16

Browse files
Fix two error handling issues in _zoneinfo.load_data()
1 parent 20e6c2f commit d888f16

2 files changed

Lines changed: 12 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: 10 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,15 @@ 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 = 0;
1185+
if (tz_str != Py_None) {
1186+
has_tz_str = PyObject_IsTrue(tz_str);
1187+
if (has_tz_str < 0) {
1188+
goto error;
1189+
}
1190+
}
1191+
1192+
if (has_tz_str) {
11851193
if (parse_tz_str(state, tz_str, &(self->tzrule_after))) {
11861194
goto error;
11871195
}

0 commit comments

Comments
 (0)