Skip to content

Commit f5b9e2c

Browse files
committed
Explicitly check if magic number is empty
1 parent 3426052 commit f5b9e2c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/PIL/PpmImagePlugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class PpmImageFile(ImageFile.ImageFile):
5252
def _read_magic(self, magic=b""):
5353
while True: # read until next whitespace
5454
c = self.fp.read(1)
55-
if c in b_whitespace:
55+
if not c or c in b_whitespace:
5656
break
5757
magic += c
5858
if len(magic) > 6: # exceeded max magic number length
@@ -69,9 +69,9 @@ def _ignore_comment(): # ignores rest of the line; stops at CR, LF or EOF
6969
if c == b"#": # found comment, ignore it
7070
_ignore_comment()
7171
continue
72+
if not c:
73+
raise ValueError("Reached EOF while reading header")
7274
if c in b_whitespace: # found whitespace, ignore it
73-
if c == b"": # reached EOF
74-
raise ValueError("Reached EOF while reading header")
7575
continue
7676
break
7777

0 commit comments

Comments
 (0)