-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
[3.12] gh-125318: Perform sanity check in find_ttinfo to mitigate out-of-bounds read
#125824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add sanity check in :mod:`zoneinfo` to mitigate out-of-bounds read. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2205,7 +2205,15 @@ find_ttinfo(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *dt) | |||||
| } | ||||||
|
|
||||||
| unsigned char fold = PyDateTime_DATE_GET_FOLD(dt); | ||||||
| assert(fold < 2); | ||||||
|
|
||||||
| // gh-125318: out-of-bounds sanity check on non-PyDateTime types | ||||||
| if (fold >= 2) { | ||||||
| PyErr_Format(PyExc_MemoryError, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use a
Suggested change
|
||||||
| "find_ttinfo: sanity check failed, fold = %d, expected " | ||||||
| "only 0 or 1", fold); | ||||||
|
Comment on lines
+2212
to
+2213
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't particularly useful to the user. Could you give more information on what they should do? (This is almost as bad as an assertion failure--we're almost certain to get reports about this.) |
||||||
| return NULL; | ||||||
| } | ||||||
|
|
||||||
| int64_t *local_transitions = self->trans_list_wall[fold]; | ||||||
| size_t num_trans = self->num_transitions; | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertion here is unwanted, even though it's optimized out for some mysterious reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertions are always optimized out :)