From f5b9e2c43af136c13b27c393dba2caaa93d9fd02 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 4 Mar 2022 11:17:25 +1100 Subject: [PATCH] Explicitly check if magic number is empty --- src/PIL/PpmImagePlugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PIL/PpmImagePlugin.py b/src/PIL/PpmImagePlugin.py index bb0972bf8..89fbc6f34 100644 --- a/src/PIL/PpmImagePlugin.py +++ b/src/PIL/PpmImagePlugin.py @@ -52,7 +52,7 @@ class PpmImageFile(ImageFile.ImageFile): def _read_magic(self, magic=b""): while True: # read until next whitespace c = self.fp.read(1) - if c in b_whitespace: + if not c or c in b_whitespace: break magic += c if len(magic) > 6: # exceeded max magic number length @@ -69,9 +69,9 @@ class PpmImageFile(ImageFile.ImageFile): if c == b"#": # found comment, ignore it _ignore_comment() continue + if not c: + raise ValueError("Reached EOF while reading header") if c in b_whitespace: # found whitespace, ignore it - if c == b"": # reached EOF - raise ValueError("Reached EOF while reading header") continue break