Skip to content

gh-152246: Fix pure-Python zoneinfo accepting invalid seperators in POSIX TZ (Mm.w.d) rules#152247

Merged
StanFromIreland merged 4 commits into
python:mainfrom
tonghuaroot:gh-152246-zoneinfo-mmwd-separator
Jun 26, 2026
Merged

gh-152246: Fix pure-Python zoneinfo accepting invalid seperators in POSIX TZ (Mm.w.d) rules#152247
StanFromIreland merged 4 commits into
python:mainfrom
tonghuaroot:gh-152246-zoneinfo-mmwd-separator

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

The pure-Python zoneinfo parser accepted a POSIX TZ Mm.w.d transition rule whose third separator was not a period. Only the first separator is escaped in the regex (r"M(\d{1,2})\.(\d).(\d)"); the bare third . matches any single character, so for example EST5EDT,M3.2X0,M11.1.0 was accepted with X consumed as the separator. POSIX requires literal periods and the C accelerator already rejects these strings, so this is a pure-vs-C parity bug.

This escapes the third separator (\.) so the pure parser matches the C accelerator and POSIX. Every well-formed Mm.w.d rule and all bundled IANA zones still parse; only the previously-accepted malformed separators now raise ValueError.

Comment thread Misc/NEWS.d/next/Library/2026-06-26-12-50-26.gh-issue-152246.MfXMd1.rst Outdated
Comment thread Lib/test/test_zoneinfo/test_zoneinfo.py Outdated
Co-authored-by: Stan Ulbrych <stan@python.org>
@StanFromIreland

StanFromIreland commented Jun 26, 2026

Copy link
Copy Markdown
Member

The POSIX spec isn't actually explicit here, and doesn’t provide a formal grammar, but this is clearly a regex-typo (and doesn’t really make much sense in practice to allow other separators). Additionally, it's consistent with the far more used C implementation. As such, LGTM.

@StanFromIreland StanFromIreland changed the title gh-152246: Reject a POSIX TZ Mm.w.d rule with a non-period separator in pure-Python zoneinfo gh-152246: Fix pure-Python zoneinfo accepting invalid seperators in POSIX TZ (Mm.w.d) rules Jun 26, 2026
@StanFromIreland StanFromIreland added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jun 26, 2026
@StanFromIreland StanFromIreland merged commit f47acc7 into python:main Jun 26, 2026
104 of 106 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @tonghuaroot for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jun 26, 2026

Copy link
Copy Markdown

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jun 26, 2026
@bedevere-app

bedevere-app Bot commented Jun 26, 2026

Copy link
Copy Markdown

GH-152266 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 Jun 26, 2026
@bedevere-app

bedevere-app Bot commented Jun 26, 2026

Copy link
Copy Markdown

GH-152267 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jun 26, 2026
@StanFromIreland

Copy link
Copy Markdown
Member

Merged, thanks.

StanFromIreland added a commit that referenced this pull request Jun 26, 2026
…tors in POSIX TZ rules (GH-152247) (#152267)

(cherry picked from commit f47acc7)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
StanFromIreland added a commit that referenced this pull request Jun 26, 2026
…tors in POSIX TZ rules (GH-152247) (#152266)

(cherry picked from commit f47acc7)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
StanFromIreland added a commit that referenced this pull request Jun 26, 2026
…tors in POSIX TZ rules (GH-152247) (#152265)

(cherry picked from commit f47acc7)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
Co-authored-by: Stan Ulbrych <stan@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants