Skip to content

Commit cab3bb8

Browse files
[3.15] gh-152212: Reject a POSIX TZ footer with a missing std offset in pure-Python zoneinfo (GH-152213) (#152379)
(cherry picked from commit 93454fe) Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
1 parent d3eea1b commit cab3bb8

3 files changed

Lines changed: 10 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,8 @@ 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+
# The STD offset is required
676+
raise ValueError(f"Invalid STD offset in {tz_str}")
676677

677678
if dst_abbr is not None:
678679
if dst_offset := m.group("dstoff"):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix the pure-Python :mod:`zoneinfo` parser accepting a POSIX TZ string with a
2+
``std`` abbreviation but no offset. This is invalid per POSIX and now
3+
raises :exc:`ValueError`, matching the C accelerator. Patch by tonghuaroot.

0 commit comments

Comments
 (0)