Skip to content

gh-114713: Handle case of an empty bytes object passed to zoneinfo.ZoneInfo #132582

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Eclips4
Copy link
Member

@Eclips4 Eclips4 commented Apr 16, 2025

@Eclips4 Eclips4 changed the title gh-114731: Handle case of an empty bytes object passed to zoneinfo.ZoneInfo gh-114713: Handle case of an empty bytes object passed to zoneinfo.ZoneInfo Apr 16, 2025
@@ -83,10 +83,14 @@ def find_tzfile(key):


def _validate_tzfile_path(path, _base=_TEST_PATH):
if not path:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't correct.
If we pass None, instead of a TypeError we'll get a ValueError, so we need more exact check here.

@Eclips4 Eclips4 added the needs backport to 3.13 bugs and security fixes label Apr 16, 2025
Comment on lines +90 to +93
elif isinstance(path, bytes) and path == b"":
raise ValueError(
"ZoneInfo key must not be an empty bytes object"
)
Copy link
Contributor

@WolframAlph WolframAlph Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense maybe to just emit ZoneInfo key must not be empty for both string and bytes? Also, since we check for passed data types, does it make sense to also restrict them to str/bytes? Currently, passing for instance [] results in TypeError: unhashable type: 'list' somewhere down the road. Maybe worth returning meaningful exception saying what allowed types are? We anyway check passed in types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. Though I think that the current approach is wrong.
We should insert these two checks (actually, bytes objects shouldn't be passed to the zoneinfo.ZoneInfo) to C and Python implementation of ZoneInfo.__new__:

  1. Check that key is string (or subclass of string)
  2. Check that key is a non-empty string.
    WDYM?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants