René's URL Explorer Experiment


Title: `zoneinfo`: pure-Python parser accepts a POSIX TZ footer with no STD offset (C rejects) · Issue #152212 · python/cpython · GitHub

Open Graph Title: `zoneinfo`: pure-Python parser accepts a POSIX TZ footer with no STD offset (C rejects) · Issue #152212 · python/cpython

X Title: `zoneinfo`: pure-Python parser accepts a POSIX TZ footer with no STD offset (C rejects) · Issue #152212 · python/cpython

Description: Bug description A POSIX TZ string requires an offset after the std abbreviation (e.g. EST5). When the offset is missing and the std field is just an abbreviation (AAA, A, AA, B, ...), the two zoneinfo implementations disagree: The C acce...

Open Graph Description: Bug description A POSIX TZ string requires an offset after the std abbreviation (e.g. EST5). When the offset is missing and the std field is just an abbreviation (AAA, A, AA, B, ...), the two zonei...

X Description: Bug description A POSIX TZ string requires an offset after the std abbreviation (e.g. EST5). When the offset is missing and the std field is just an abbreviation (AAA, A, AA, B, ...), the two zonei...

Opengraph URL: https://github.com/python/cpython/issues/152212

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`zoneinfo`: pure-Python parser accepts a POSIX TZ footer with no STD offset (C rejects)","articleBody":"### Bug description\n\nA POSIX TZ string requires an offset after the std abbreviation (e.g. `EST5`). When the\noffset is missing and the std field is just an abbreviation (`AAA`, `A`, `AA`, `B`, ...),\nthe two `zoneinfo` implementations disagree:\n\n- The C accelerator (`_zoneinfo`) raises `ValueError: Invalid STD offset`.\n- The pure-Python parser (`zoneinfo._zoneinfo`) silently accepts it and builds a\n  fixed-offset-0 zone named after the abbreviation.\n\nReproduced by embedding the footer in a minimal TZif v2 file and loading it through\n`ZoneInfo.from_file` against both implementations:\n\n```pycon\n>>> import io, struct, datetime as dt\n>>> import _zoneinfo                 # C accelerator\n>>> import zoneinfo._zoneinfo        # pure-Python reference\n>>>\n>>> def tzif(footer):               # minimal TZif v2: 0 transitions, 1 ttinfo (UTC), footer\n...     def block():\n...         return (b\"TZif\" + b\"\\x32\" + b\"\\x00\" * 15\n...                 + struct.pack(\">6l\", 0, 0, 0, 0, 1, 4)\n...                 + struct.pack(\">lbb\", 0, 0, 0) + b\"UTC\\x00\")\n...     return block() + block() + b\"\\n\" + footer.encode() + b\"\\n\"\n...\n>>> # C accelerator: rejects the offset-less std field\n>>> _zoneinfo.ZoneInfo.from_file(io.BytesIO(tzif(\"AAA\")), key=\"AAA\")\nTraceback (most recent call last):\n  ...\nValueError: Invalid STD offset in b'AAA'\n>>>\n>>> # pure-Python: accepts it as a fixed offset-0 zone\n>>> zi = zoneinfo._zoneinfo.ZoneInfo.from_file(io.BytesIO(tzif(\"AAA\")), key=\"AAA\")\n>>> zi.utcoffset(dt.datetime(2025, 1, 15, 12))\ndatetime.timedelta(0)\n>>> zi.tzname(dt.datetime(2025, 1, 15, 12))\n'AAA'\n```\n\nThe same divergence occurs for `A`, `AA`, `B`, and any other bare std abbreviation.\n\n### Root cause\n\n`Lib/zoneinfo/_zoneinfo.py`, in `_parse_tz_str`, the std-offset branch (around L669-675 on\n`main`):\n\n```python\n    if std_offset := m.group(\"stdoff\"):\n        try:\n            std_offset = _parse_tz_delta(std_offset)\n        except ValueError as e:\n            raise ValueError(f\"Invalid STD offset in {tz_str}\") from e\n    else:\n        std_offset = 0          # \u003c-- treats a missing std offset as 0\n```\n\nWhen the regex captures a std abbreviation but no `stdoff` group, the `else` branch\ndefaults the offset to `0` instead of raising. The C accelerator has no such default and\nraises `Invalid STD offset` when the std offset is absent.\n\n### Spec\n\nPOSIX.1-2024 (Issue 8), §8.3 \"Other Environment Variables\" (the `TZ` rule format) gives\nthe std field as `std offset` and states that the offset following `std` *shall be\nrequired*; only the `dst` offset is optional (DST then defaults to one hour ahead of std).\nRFC 8536 §3.3 (\"TZif Footer\"), which governs the embedded TZ-string footer of a TZif file,\nspecifies that the footer uses the POSIX `TZ` grammar from Base Definitions §8.3; its\nextensions (§3.3.1) only widen the offset hour range and add year-round-DST syntax; none\nrelax the required std offset. So a footer like `AAA` is not a valid POSIX TZ string, and\nthe C accelerator's rejection is the correct behavior. (For reference, macOS libc likewise\ntreats `TZ=AAA` as invalid and falls back to UTC: `tzname=('UTC', 'UTC')`, offset 0.)\n\n### Suggested fix\n\nMake the pure-Python parser reject a missing std offset, matching the C accelerator. The\n`else` branch becomes a `raise` with the same message wording the accelerator uses:\n\n```python\n    else:\n        raise ValueError(f\"Invalid STD offset in {tz_str}\")\n```\n\nThis is non-breaking for real data: across the full IANA database (598 zones loaded\nthrough the pure parser) no zone is newly rejected, and well-formed strings such as `EST5`,\n`\u003cABC>5`, and `AAA5` continue to parse identically on both implementations. A PR with the\none-line fix and a regression test (covering `AAA`, `A`, `AA`, `B` in `test_invalid_tzstr`,\nwhich runs against both `TZStrTest` and `CTZStrTest`) follows.\n\n### Environment\n\n- Reproduced on `main` (3.16.0a0).\n- The pure-Python parser is used whenever the `_zoneinfo` C extension is unavailable, and\n  is also reachable directly via `zoneinfo._zoneinfo`.\n- The same `else: std_offset = 0` code is present on 3.13, 3.14, and 3.15, which are\n  likewise affected.\n\nThis is a correctness/parity issue, not a security issue.\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-152213\n* gh-152377\n* gh-152378\n* gh-152379\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/tonghuaroot","@type":"Person","name":"tonghuaroot"},"datePublished":"2026-06-25T15:13:56Z","url":"https://github.com/python/cpython/issues/152212"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:cce14afd-5542-a057-1472-e951be6bb105
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA8C0:DB09F:42D750B:5532AF1:6B023AA1
html-safe-nonce3c96a261e4e1db101a5025e0d1975705cd8cc85f402dd4a410da77b7f01c99fc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOEMwOkRCMDlGOjQyRDc1MEI6NTUzMkFGMTo2QjAyM0FBMSIsInZpc2l0b3JfaWQiOiIyODIyNDg2OTY3ODAyMDE4NDY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac75bc77000aca7baef50193d662154cc06d2f1bd1c90204401c22ac7dea88cd9b
hovercard-subject-tagissue:4745068326
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/152212/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ab20c97209293f8dea687c2b43cc51bcfd05a34df1719cb180eec72009aac6f8/python/cpython/issues/152212
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ab20c97209293f8dea687c2b43cc51bcfd05a34df1719cb180eec72009aac6f8/python/cpython/issues/152212
og:image:altBug description A POSIX TZ string requires an offset after the std abbreviation (e.g. EST5). When the offset is missing and the std field is just an abbreviation (AAA, A, AA, B, ...), the two zonei...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametonghuaroot
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/152212#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F152212
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F152212
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/152212
Reloadhttps://github.com/python/cpython/issues/152212
Reloadhttps://github.com/python/cpython/issues/152212
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/152212
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/152212
#152213https://github.com/python/cpython/pull/152213
zoneinfo: pure-Python parser accepts a POSIX TZ footer with no STD offset (C rejects)https://github.com/python/cpython/issues/152212#top
#152213https://github.com/python/cpython/pull/152213
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/tonghuaroot
tonghuaroothttps://github.com/tonghuaroot
on Jun 25, 2026https://github.com/python/cpython/issues/152212#issue-4745068326
gh-152212: Reject a POSIX TZ footer with a missing std offset in pure-Python zoneinfo #152213https://github.com/python/cpython/pull/152213
[3.13] gh-152212: Reject a POSIX TZ footer with a missing std offset in pure-Python zoneinfo (GH-152213) #152377https://github.com/python/cpython/pull/152377
[3.14] gh-152212: Reject a POSIX TZ footer with a missing std offset in pure-Python zoneinfo (GH-152213) #152378https://github.com/python/cpython/pull/152378
[3.15] gh-152212: Reject a POSIX TZ footer with a missing std offset in pure-Python zoneinfo (GH-152213) #152379https://github.com/python/cpython/pull/152379
StanFromIrelandhttps://github.com/StanFromIreland
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
on Jun 25, 2026https://github.com/python/cpython/issues/152212#event-27217427573
StanFromIrelandhttps://github.com/StanFromIreland
Date and time issues 🕰️https://github.com/orgs/python/projects/21
on Jun 25, 2026https://github.com/python/cpython/issues/152212#event-27217438688
tonghuaroothttps://github.com/tonghuaroot
on Jun 27, 2026https://github.com/python/cpython/issues/152212#event-27268969441
pythongh-152212: Add STD-offset-required comment and tighten NEWS per…https://github.com/tonghuaroot/cpython/commit/aec9aea6c8a62f015044b1357385ee2bf0abff2e
pythongh-152212https://github.com/python/cpython/issues/152212
aec9aeahttps://github.com/tonghuaroot/cpython/commit/aec9aea6c8a62f015044b1357385ee2bf0abff2e
StanFromIrelandhttps://github.com/StanFromIreland
on Jun 27, 2026https://github.com/python/cpython/issues/152212#event-27276611065
gh-152212: Reject a POSIX TZ footer with a missing std offset in pure…https://github.com/python/cpython/commit/93454fe0daa2b29e8fefbe76aed7af4fa1eb8623
gh-152212https://github.com/python/cpython/issues/152212
93454fehttps://github.com/python/cpython/commit/93454fe0daa2b29e8fefbe76aed7af4fa1eb8623
StanFromIrelandhttps://github.com/StanFromIreland
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#152213https://github.com/python/cpython/pull/152213
on Jun 27, 2026https://github.com/python/cpython/issues/152212#event-27276611077
github-project-automationhttps://github.com/apps/github-project-automation
Date and time issues 🕰️https://github.com/orgs/python/projects/21
on Jun 27, 2026https://github.com/python/cpython/issues/152212
StanFromIrelandhttps://github.com/StanFromIreland
on Jun 27, 2026https://github.com/python/cpython/issues/152212#event-27277016291
[3.13] gh-152212: Reject a POSIX TZ footer with a missing std offset …https://github.com/python/cpython/commit/8744d058ea338bf8a0dfd8f2d21e6120ec386f81
gh-152212https://github.com/python/cpython/issues/152212
8744d05https://github.com/python/cpython/commit/8744d058ea338bf8a0dfd8f2d21e6120ec386f81
[3.14] gh-152212: Reject a POSIX TZ footer with a missing std offset …https://github.com/python/cpython/commit/daa378edf90bc4c31a3665fb18e455e228f14fc6
gh-152212https://github.com/python/cpython/issues/152212
daa378ehttps://github.com/python/cpython/commit/daa378edf90bc4c31a3665fb18e455e228f14fc6
[3.15] gh-152212: Reject a POSIX TZ footer with a missing std offset …https://github.com/python/cpython/commit/cab3bb8e3057da6035fc1967cb1eacf1bbf89e27
gh-152212https://github.com/python/cpython/issues/152212
cab3bb8https://github.com/python/cpython/commit/cab3bb8e3057da6035fc1967cb1eacf1bbf89e27
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/152212
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/152212
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
Date and time issues 🕰️https://github.com/orgs/python/projects/21
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.