Skip to content

Missing error checks in the _zoneinfo.load_data() #156067

Description

@StanFromIreland

Bug report

Bug description:

PyObject_IsTrue(tz_str) is used directly as a condition, so a -1 return counts as true and the exception is carried into a successful return:

if (tz_str != Py_None && PyObject_IsTrue(tz_str)) {

PyLong_AsSsize_t() is checked with == -1 but without PyErr_Occurred(), so a transition index of -1 takes the error path with no exception set (although technically not reachable from a TZif file, since _common.load_data() unpacks the indices as unsigned bytes):

cpython/Modules/_zoneinfo.c

Lines 1072 to 1075 in 20e6c2f

Py_ssize_t cur_trans_idx = PyLong_AsSsize_t(num);
if (cur_trans_idx == -1) {
goto error;
}

Found by @devdanzin ❤️

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Labels

extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions