mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +03:00
Only read a maximum of 100 bytes at a time
This commit is contained in:
parent
d402fe0b17
commit
cb2243713c
|
@ -39,14 +39,18 @@ class ImtImageFile(ImageFile.ImageFile):
|
||||||
# Quick rejection: if there's not a LF among the first
|
# Quick rejection: if there's not a LF among the first
|
||||||
# 100 bytes, this is (probably) not a text header.
|
# 100 bytes, this is (probably) not a text header.
|
||||||
|
|
||||||
if b"\n" not in self.fp.read(100):
|
buffer = self.fp.read(100)
|
||||||
|
if b"\n" not in buffer:
|
||||||
raise SyntaxError("not an IM file")
|
raise SyntaxError("not an IM file")
|
||||||
self.fp.seek(0)
|
|
||||||
|
|
||||||
xsize = ysize = 0
|
xsize = ysize = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
if buffer:
|
||||||
|
s = buffer[:1]
|
||||||
|
buffer = buffer[1:]
|
||||||
|
else:
|
||||||
s = self.fp.read(1)
|
s = self.fp.read(1)
|
||||||
if not s:
|
if not s:
|
||||||
break
|
break
|
||||||
|
@ -55,7 +59,12 @@ class ImtImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
# image data begins
|
# image data begins
|
||||||
self.tile = [
|
self.tile = [
|
||||||
("raw", (0, 0) + self.size, self.fp.tell(), (self.mode, 0, 1))
|
(
|
||||||
|
"raw",
|
||||||
|
(0, 0) + self.size,
|
||||||
|
self.fp.tell() - len(buffer),
|
||||||
|
(self.mode, 0, 1),
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
break
|
break
|
||||||
|
@ -63,8 +72,11 @@ class ImtImageFile(ImageFile.ImageFile):
|
||||||
else:
|
else:
|
||||||
|
|
||||||
# read key/value pair
|
# read key/value pair
|
||||||
# FIXME: dangerous, may read whole file
|
if b"\n" not in buffer:
|
||||||
s = s + self.fp.readline()
|
buffer += self.fp.read(100)
|
||||||
|
lines = buffer.split(b"\n")
|
||||||
|
s += lines.pop(0)
|
||||||
|
buffer = b"\n".join(lines)
|
||||||
if len(s) == 1 or len(s) > 100:
|
if len(s) == 1 or len(s) > 100:
|
||||||
break
|
break
|
||||||
if s[0] == ord(b"*"):
|
if s[0] == ord(b"*"):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user