gh-152212: Reject a POSIX TZ footer with a missing std offset in pure-Python zoneinfo#152213
Conversation
…n pure-Python zoneinfo The pure-Python _parse_tz_str defaulted a missing std offset to 0, so a POSIX TZ footer with a bare std abbreviation and no offset (e.g. 'AAA') was silently accepted as a fixed offset-0 zone. POSIX requires the offset after std, and the C accelerator already rejects it, so the pure-Python parser now raises ValueError to match.
| "PST8PDT", # DST but no transition specified | ||
| # gh-152212: the std offset is required (POSIX TZ grammar) | ||
| "AAA", | ||
| "A", |
There was a problem hiding this comment.
I was going to say these are rejected for another reason, i.e. because of the spec's required length:
three byte minimum length
But of course, we don't enforce that. However, I'm also not sure if this is just part of the 2024 updated spec, and I don't have time to check right now. I'll put this on my to-do list.
|
Thanks @tonghuaroot for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
Thanks @tonghuaroot for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Thanks @tonghuaroot for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-152377 is a backport of this pull request to the 3.13 branch. |
|
GH-152378 is a backport of this pull request to the 3.14 branch. |
|
GH-152379 is a backport of this pull request to the 3.15 branch. |
The pure-Python
zoneinfo._parse_tz_strdefaults a missing std offset to0(else: std_offset = 0), so a POSIX TZ footer with a bare std abbreviation and no offset (AAA,A,AA,B) is silently accepted as a fixed offset-0 zone. POSIX requires the offset afterstd(Issue 8 §8.3), and the C accelerator already raisesValueError: Invalid STD offset, so this makes the pure-Python parser raise to match.Adds
AAA/A/AA/Btotest_invalid_tzstr, which runs against bothTZStrTest(pure) andCTZStrTest(C). Non-breaking: all 598 IANA zones still parse, and well-formed strings (EST5,<ABC>5,AAA5) are unaffected.Fixes #152212.
zoneinfo: pure-Python parser accepts a POSIX TZ footer with no STD offset (C rejects) #152212