We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 61ee048 commit be21254Copy full SHA for be21254
2 files changed
Lib/test/test_zoneinfo/test_zoneinfo.py
@@ -252,6 +252,8 @@ def test_bad_zones(self):
252
bad_zones = [
253
b"", # Empty file
254
b"AAAA3" + b" " * 15, # Bad magic
255
+ # Truncated V2 file (infinite loop DoS)
256
+ b"TZif2" + (b"\x00" * 39) + b"TZif2" + (b"\x00" * 39) + b"\n" + b"Part",
257
]
258
259
for bad_zone in bad_zones:
Lib/zoneinfo/_common.py
@@ -119,8 +119,10 @@ def get_abbr(idx):
119
assert c == b"\n", c
120
121
tz_bytes = b""
122
- while (c := fobj.read(1)) != b"\n":
123
- tz_bytes += c
+ line = fobj.readline()
+ if not line.endswith(b"\n"):
124
+ raise ValueError("Invalid TZif file: unexpected end of file")
125
+ tz_bytes = line.rstrip(b"\n")
126
127
tz_str = tz_bytes
128
else:
0 commit comments