Skip to content

Commit babe3da

Browse files
committed
gh-152212: Reject a POSIX TZ footer with a missing std offset in 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.
1 parent 56ae0b8 commit babe3da

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/test/test_zoneinfo/test_zoneinfo.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,11 @@ def test_extreme_tzstr(self):
11421142
def test_invalid_tzstr(self):
11431143
invalid_tzstrs = [
11441144
"PST8PDT", # DST but no transition specified
1145+
# gh-152212: the std offset is required (POSIX TZ grammar)
1146+
"AAA",
1147+
"A",
1148+
"AA",
1149+
"B",
11451150
"+11", # Unquoted alphanumeric
11461151
"GMT,M3.2.0/2,M11.1.0/3", # Transition rule but no DST
11471152
"GMT0+11,M3.2.0/2,M11.1.0/3", # Unquoted alphanumeric in DST

Lib/zoneinfo/_zoneinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ def _parse_tz_str(tz_str):
672672
except ValueError as e:
673673
raise ValueError(f"Invalid STD offset in {tz_str}") from e
674674
else:
675-
std_offset = 0
675+
raise ValueError(f"Invalid STD offset in {tz_str}")
676676

677677
if dst_abbr is not None:
678678
if dst_offset := m.group("dstoff"):
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fixed a parity bug in the pure-Python :mod:`zoneinfo` implementation, which
2+
accepted a POSIX TZ footer whose ``std`` field had no offset (for example
3+
``AAA``), silently building a fixed offset-0 zone. Such a string is invalid per
4+
POSIX (the offset following ``std`` is required), and the C accelerator already
5+
rejects it; the pure-Python parser now raises :exc:`ValueError` to match.
6+
Patch by tonghuaroot.

0 commit comments

Comments
 (0)