File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed
Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,8 @@ def test_bad_zones(self):
252252 bad_zones = [
253253 b"" , # Empty file
254254 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" ,
255257 ]
256258
257259 for bad_zone in bad_zones :
Original file line number Diff line number Diff line change @@ -119,8 +119,10 @@ def get_abbr(idx):
119119 assert c == b"\n " , c
120120
121121 tz_bytes = b""
122- while (c := fobj .read (1 )) != b"\n " :
123- tz_bytes += c
122+ line = fobj .readline ()
123+ if not line .endswith (b"\n " ):
124+ raise ValueError ("Invalid TZif file: unexpected end of file" )
125+ tz_bytes = line .rstrip (b"\n " )
124126
125127 tz_str = tz_bytes
126128 else :
You can’t perform that action at this time.
0 commit comments