Add token limit

This commit is contained in:
Piolie 2021-01-06 01:07:14 -03:00
parent d2ad27d70a
commit 4dbe244e42

View File

@ -87,6 +87,8 @@ class PpmImageFile(ImageFile.ImageFile):
if c in B_WHITESPACE: # token ended if c in B_WHITESPACE: # token ended
break break
token += c token += c
if len(token) > 9:
raise ValueError(f"Token too long: {token}")
return token return token
def _open(self): def _open(self):
@ -109,8 +111,9 @@ class PpmImageFile(ImageFile.ImageFile):
self.mode = rawmode = mode self.mode = rawmode = mode
for ix in range(3): for ix in range(3):
token = self._read_token()
try: # check token sanity try: # check token sanity
token = int(self._read_token()) token = int(token)
except ValueError: except ValueError:
raise SyntaxError("Non-decimal-ASCII found in header") raise SyntaxError("Non-decimal-ASCII found in header")
if ix == 0: # token is the x size if ix == 0: # token is the x size