-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
BugAny unexpected behavior, until confirmed feature.Any unexpected behavior, until confirmed feature.
Description
What did you do?
Open an untruncated png image with LOAD_TRUNCATED_IMAGES==True.
What did you expect to happen?
The image is opened.
What actually happened?
The image is not opened. (But image converted with gimp opens)
Loaded PIL.ImageFile.LOAD_TRUNCATED_IMAGES=False
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~/.virtualenvs/venv/lib64/python3.8/site-packages/PIL/PngImagePlugin.py in load_end(self)
939 try:
--> 940 self.png.call(cid, pos, length)
941 except UnicodeDecodeError:
~/.virtualenvs/venv/lib64/python3.8/site-packages/PIL/PngImagePlugin.py in call(self, cid, pos, length)
186 logger.debug("STREAM %r %s %s", cid, pos, length)
--> 187 return getattr(self, "chunk_" + cid.decode("ascii"))(pos, length)
188
AttributeError: 'PngStream' object has no attribute 'chunk_I'
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
<ipython-input-14-39acebf157ec> in <module>
9
10 img = PIL.Image.open(image_path)
---> 11 img.load()
12 print(f"Loaded {PIL.ImageFile.LOAD_TRUNCATED_IMAGES=}")
~/.virtualenvs/venv/lib64/python3.8/site-packages/PIL/ImageFile.py in load(self)
264 self.readonly = readonly
265
--> 266 self.load_end()
267
268 if self._exclusive_fp and self._close_exclusive_fp_after_loading:
~/.virtualenvs/venv/lib64/python3.8/site-packages/PIL/PngImagePlugin.py in load_end(self)
947 except AttributeError:
948 logger.debug("%r %s %s (unknown)", cid, pos, length)
--> 949 s = ImageFile._safe_read(self.fp, length)
950 if cid[1:2].islower():
951 self.private_chunks.append((cid, s, True))
~/.virtualenvs/venv/lib64/python3.8/site-packages/PIL/ImageFile.py in _safe_read(fp, size)
566 size -= len(block)
567 if sum(len(d) for d in data) < size:
--> 568 raise OSError("Truncated File Read")
569 return b"".join(data)
570
OSError: Truncated File Read
What are your OS, Python and Pillow versions?
- OS: Linux 5.11.17-300.fc34.x86_64 Merge pull request from @shuge #1 SMP Wed Apr 28 14:21:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
- Python: 3.8.9
- Pillow: 8.2.0
import PIL
image_path = 'error_image.png'
img = PIL.Image.open(image_path)
img.load()
print(f"Loaded {PIL.ImageFile.LOAD_TRUNCATED_IMAGES=}")
PIL.ImageFile.LOAD_TRUNCATED_IMAGES = True
img = PIL.Image.open(image_path)
img.load()
print(f"Loaded {PIL.ImageFile.LOAD_TRUNCATED_IMAGES=}")xvolica and SuoSiFire
Metadata
Metadata
Assignees
Labels
BugAny unexpected behavior, until confirmed feature.Any unexpected behavior, until confirmed feature.

