From f4dc9f458788dfbeb6e2f173679df42254a0f116 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 30 Jun 2025 11:09:21 +0200 Subject: [PATCH 1/3] gh-85702: Catch PermissionError in zoneinfo.load_tzdata() --- Lib/zoneinfo/_common.py | 7 +++++-- .../Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst diff --git a/Lib/zoneinfo/_common.py b/Lib/zoneinfo/_common.py index 6e05abc32394bc..d552541998d357 100644 --- a/Lib/zoneinfo/_common.py +++ b/Lib/zoneinfo/_common.py @@ -9,9 +9,12 @@ def load_tzdata(key): resource_name = components[-1] try: - return resources.files(package_name).joinpath(resource_name).open("rb") + path = resources.files(package_name).joinpath(resource_name) + if path.is_dir(): + raise IsADirectoryError + return path.open("rb") except (ImportError, FileNotFoundError, UnicodeEncodeError, IsADirectoryError): - # There are three types of exception that can be raised that all amount + # There are four types of exception that can be raised that all amount # to "we cannot find this key": # # ImportError: If package_name doesn't exist (e.g. if tzdata is not diff --git a/Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst b/Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst new file mode 100644 index 00000000000000..a060a9c0c47608 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst @@ -0,0 +1,3 @@ +If ``zoneinfo._common.load_tzdata`` is given a package without a resource a +``ZoneInfoNotFoundError`` is raised rather than a :exc:`PermissionError`. +Patch by Victor Stinner. From fd9ce71fffed0e3f08ba40b8dffba37e1a0fe687 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 30 Jun 2025 11:38:39 +0200 Subject: [PATCH 2/3] Add comment --- Lib/zoneinfo/_common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/zoneinfo/_common.py b/Lib/zoneinfo/_common.py index d552541998d357..03cc42149f9b74 100644 --- a/Lib/zoneinfo/_common.py +++ b/Lib/zoneinfo/_common.py @@ -10,6 +10,7 @@ def load_tzdata(key): try: path = resources.files(package_name).joinpath(resource_name) + # gh-85702: Prevent PermissionError on Windows if path.is_dir(): raise IsADirectoryError return path.open("rb") From 5ebcb827e3dbfb0e6ed388434c4865b5efb431f5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 30 Jun 2025 15:34:21 +0200 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst Co-authored-by: Peter Bierma --- .../next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst b/Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst index a060a9c0c47608..fc13eb1d9e0c99 100644 --- a/Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst +++ b/Misc/NEWS.d/next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst @@ -1,3 +1,3 @@ If ``zoneinfo._common.load_tzdata`` is given a package without a resource a -``ZoneInfoNotFoundError`` is raised rather than a :exc:`PermissionError`. +:exc:`zoneinfo.ZoneInfoNotFoundError` is raised rather than a :exc:`PermissionError`. Patch by Victor Stinner.