From e86ac729953febddc13c59fb15be6d1cc6b80146 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Mon, 30 Jun 2025 16:58:18 +0200 Subject: [3.14] gh-85702: Catch PermissionError in zoneinfo.load_tzdata() (GH-136117) (#136128) gh-85702: Catch PermissionError in zoneinfo.load_tzdata() (GH-136117) (cherry picked from commit ee47670e8b8648b14fd4cb64a9d47d6ed3c5b6b7) Co-authored-by: Victor Stinner Co-authored-by: Peter Bierma --- Lib/zoneinfo/_common.py | 8 ++++++-- .../next/Library/2025-06-30-11-12-24.gh-issue-85702.0Lrbwu.rst | 3 +++ 2 files changed, 9 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 6e05abc..03cc421 100644 --- a/Lib/zoneinfo/_common.py +++ b/Lib/zoneinfo/_common.py @@ -9,9 +9,13 @@ 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) + # gh-85702: Prevent PermissionError on Windows + 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 0000000..fc13eb1 --- /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 +:exc:`zoneinfo.ZoneInfoNotFoundError` is raised rather than a :exc:`PermissionError`. +Patch by Victor Stinner. -- cgit v0.12