Skip to content

gh-160420: Reject drive letters in ZoneInfo key components on Windows - #160421

Merged
gpshead merged 2 commits into
python:mainfrom
gpshead:scanfix-tzpath-izmaolcq
Oct 23, 2026
Merged

gpshead merged 2 commits into
python:mainfrom
gpshead:scanfix-tzpath-izmaolcq

Conversation

@gpshead

@gpshead gpshead commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

_validate_tzfile_path() now also checks each /-separated component of a ZoneInfo key with os.path.splitroot() and raises ValueError if it has a drive or root. Before, a key such as America/C:\Windows\win.ini passed validation on Windows, and load_tzdata() joined C:\Windows\win.ini to the tzdata package directory, which replaced it. No POSIX key changes behaviour, and all keys in the system time zone database still validate under ntpath.

I could not run this on Windows. The new test runs the validator with os.path swapped for ntpath, so it exercises the Windows rules on every platform, but the end-to-end behaviour with tzdata installed on Windows is checked by code inspection only.

The 3.11 backport needs a manual port: os.path.splitroot() is new in 3.12, so the automated cherry-pick would produce code that fails there. On 3.11 the check can be written as os.path.splitdrive(component)[0] or os.path.isabs(component).

Fixes #160420

ANT-2026-IZMAOLCQ

…indows

A key such as "America/C:\file" passed validation, and the tzdata
loader then joined "C:\file" to the package directory, which replaced
it.

ANT-2026-IZMAOLCQ
@gpshead
gpshead marked this pull request as ready for review October 23, 2026 16:38
@gpshead
gpshead enabled auto-merge (squash) October 23, 2026 16:40
@StanFromIreland StanFromIreland removed needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes labels Oct 23, 2026
@@ -0,0 +1,4 @@
Fix :class:`zoneinfo.ZoneInfo` on Windows accepting keys in which a component
after a ``/`` starts with a drive letter, such as ``America/C:\file``. Such a
key could open a file outside the ``tzdata`` package; it now raises

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should refer to TZPATH rather than tzdata.

@gpshead
gpshead merged commit 0615b5c into python:main Oct 23, 2026
64 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 23, 2026

Copy link
Copy Markdown

GH-160447 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 23, 2026
@bedevere-app

bedevere-app Bot commented Oct 23, 2026

Copy link
Copy Markdown

GH-160448 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 23, 2026
@gpshead gpshead added the sprint label Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zoneinfo.ZoneInfo accepts keys with a drive letter in a later component on Windows

2 participants