Skip to content
Merged
2 changes: 2 additions & 0 deletions Lib/test/test_zoneinfo/test_zoneinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ def test_bad_zones(self):
bad_zones = [
b"", # Empty file
b"AAAA3" + b" " * 15, # Bad magic
# Truncated V2 file (infinite loop DoS)
b"TZif2" + (b"\x00" * 39) + b"TZif2" + (b"\x00" * 39) + b"\n" + b"Part",
]

for bad_zone in bad_zones:
Expand Down
6 changes: 4 additions & 2 deletions Lib/zoneinfo/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ def get_abbr(idx):
assert c == b"\n", c

tz_bytes = b""
while (c := fobj.read(1)) != b"\n":
tz_bytes += c
line = fobj.readline()
if not line.endswith(b"\n"):
raise ValueError("Invalid TZif file: unexpected end of file")
tz_bytes = line.rstrip(b"\n")

tz_str = tz_bytes
else:
Expand Down
Loading