-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
I’m one of the maintainers of Loris, an image server that uses Pillow. One of our users has reported corruption of TIFF images that I believe comes from Pillow (loris-imageserver/loris#503).
This example downloads the TIFF, and converts it to a JPEG (image from https://elifesciences.org/digests/55692/could-some-antibiotics-be-immune-stimulants):
import hashlib
import os
import shutil
from urllib.request import urlretrieve
from PIL import Image
# Download the image
filename, _ = urlretrieve("https://prod-elife-published.s3.amazonaws.com/digests/55692/digest-55692.tif")
# Expected size: 219528
# Expected hash: 01ddb8885aa5252b41be06dcdf36703932be24436013d5ea65ca9b1fd675258a
print(f"size = {os.stat(filename).st_size}")
print(f"sha256 = {hashlib.sha256(open(filename, 'rb').read()).hexdigest()}")
# Open the image as a TIF; save as a JPEG
im = Image.open(filename)
im.save("digest-55692.jpg")This table shows the output from three versions of Pillow (resized for readability):
![]() |
![]() |
![]() |
| 4.3.0 | 5.0.0 (next version) | 7.1.2 (latest) |
The corruption is not deterministic; running the script repeatedly gets images that look different every time.
I have attached a zip archive (pillow_test_cases.zip) which includes the original TIFF, and the three JPEG outputs.
I produced these examples running inside a Docker container, built with the following Dockerfile template and varying the version of Pillow:
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y python3 python3-pip
RUN pip3 install Pillow==5.0.0
COPY example.py /
CMD ["python3", "/example.py"]We've had issues with TIFFs in Loris/Pillow in the past, which led to #2926. I wonder if this issue has a similar cause?


