mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-13 13:16:52 +03:00
Allow PyDecoder to pass truncated data to C decoder
This commit is contained in:
parent
e32a94e835
commit
0d5a2d2b83
|
@ -174,13 +174,14 @@ class PpmPlainDecoder(ImageFile.PyDecoder):
|
||||||
are exactly one byte, and so the inter-token whitespace is optional.
|
are exactly one byte, and so the inter-token whitespace is optional.
|
||||||
"""
|
"""
|
||||||
decoded_data = bytearray()
|
decoded_data = bytearray()
|
||||||
total_bytes = self.size
|
total_bytes = self.state.xsize * self.state.ysize
|
||||||
|
|
||||||
comment_spans = False
|
comment_spans = False
|
||||||
while len(decoded_data) != total_bytes:
|
while len(decoded_data) != total_bytes:
|
||||||
block = self._read_block() # read next block
|
block = self._read_block() # read next block
|
||||||
if not block:
|
if not block:
|
||||||
raise ValueError("Reached EOF while reading data")
|
# eof
|
||||||
|
break
|
||||||
|
|
||||||
while block and comment_spans:
|
while block and comment_spans:
|
||||||
comment_end = self._find_comment_end(block)
|
comment_end = self._find_comment_end(block)
|
||||||
|
@ -206,7 +207,7 @@ class PpmPlainDecoder(ImageFile.PyDecoder):
|
||||||
maxval = 2 ** (31 if depth == 32 else depth) - 1
|
maxval = 2 ** (31 if depth == 32 else depth) - 1
|
||||||
max_len = 10
|
max_len = 10
|
||||||
bytes_per_sample = depth // 8
|
bytes_per_sample = depth // 8
|
||||||
total_bytes = self.size * channels * bytes_per_sample
|
total_bytes = self.state.xsize * self.state.ysize * channels * bytes_per_sample
|
||||||
|
|
||||||
comment_spans = False
|
comment_spans = False
|
||||||
half_token = False
|
half_token = False
|
||||||
|
@ -216,7 +217,8 @@ class PpmPlainDecoder(ImageFile.PyDecoder):
|
||||||
if half_token:
|
if half_token:
|
||||||
block = bytearray(b" ") # flush half_token
|
block = bytearray(b" ") # flush half_token
|
||||||
else:
|
else:
|
||||||
raise ValueError("Reached EOF while reading data")
|
# eof
|
||||||
|
break
|
||||||
|
|
||||||
while block and comment_spans:
|
while block and comment_spans:
|
||||||
comment_end = self._find_comment_end(block)
|
comment_end = self._find_comment_end(block)
|
||||||
|
@ -254,7 +256,6 @@ class PpmPlainDecoder(ImageFile.PyDecoder):
|
||||||
return decoded_data
|
return decoded_data
|
||||||
|
|
||||||
def decode(self, buffer):
|
def decode(self, buffer):
|
||||||
self.size = self.state.xsize * self.state.ysize
|
|
||||||
rawmode = self.args[0]
|
rawmode = self.args[0]
|
||||||
|
|
||||||
if self.mode == "1":
|
if self.mode == "1":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user