Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corruption of TIFF images that was introduced in 5.0.0 #4621

Closed
alexwlchan opened this issue May 12, 2020 · 3 comments
Closed

Corruption of TIFF images that was introduced in 5.0.0 #4621

alexwlchan opened this issue May 12, 2020 · 3 comments
Labels

Comments

@alexwlchan
Copy link
Contributor

alexwlchan commented May 12, 2020

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.05.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?

@radarhere radarhere added the TIFF label May 13, 2020
@radarhere
Copy link
Member

Thanks for your detailed report.

Testing, I find that the problem begins with #2899, when we removed our internal TIFF LZW decoder.

Trying to look for an unusual setup in the TIFF file, I see that it has a Planar Configuration value of 2 and LZW compression. All of the test images from Pillow that I could open with Planar Configuration 2 are raw compression, so I suspect the use of compression plus separate component planes is causing the difficulty.

@kkopachev
Copy link
Contributor

Looking at TiffDecode.c, Planar Configuration = 2 is not supported at all. So all compressed tiffs would fail in that case.

@radarhere
Copy link
Member

radarhere commented Mar 28, 2021

Resolved by #5364

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants