Skip to content

TIFF_LZW decompression is incorrect for 16bpc image #2839

Closed

Description

@giorgiosironi

Pillow was refusing to open this TIFF in version 4.2.1. In version 4.3.0, it loads it, but then saving it in any format including TIFF produces a silent corruption. Python 2.7.14 in both cases.

This is the reproducing script:

from PIL import Image                                                                                                                      

# https://s3-external-1.amazonaws.com/prod-elife-published/articles/32330/elife-32330-fig1-v1.tif 
src_fp = 'elife-32330-fig1-v1.tif'
im = Image.open(src_fp)
target_fp = open('result.tif', 'w')
im.save(target_fp)

In 4.2.1:

  File "reproducing.py", line 5, in <module>
    im = Image.open(src_fp)
  File "/opt/loris/venv/local/lib/python2.7/site-packages/PIL/Image.py", line 2519, in open
    % (filename if filename else fp))
IOError: cannot identify image file 'elife-32330-fig1-v1.tif'

In 4.3.0, no output, file gets stored and corrupted.
elife-32330-fig1-v1.tif.gz
result.tif.gz
converting to PNG

I tried to track how the Image class changed from 4.2.1 to 4.3.0, but there were too many changes to identify the source. I don't expect it to start to work, but to continue throwing an exception if it can't be read safely.

Activity

  1. changed the title [-]TIFF that could not be loaded gets corrupted by Pillow 4.3.0[/-] [+]TIFF that could not be loaded in 4.2.1 gets silently corrupted in 4.3.0[/+] on Nov 7, 2017
  2. wiredfool commented on Nov 7, 2017

    @wiredfool
    Member

    If you use libtiff instead of the internal tiff decoder, it works:

    from PIL import Image, TiffImagePlugin
    TiffImagePlugin.READ_LIBTIFF=True
    
    im = Image.open('issue_2839.tif')
    im.show()
    

    This image is a 16bit RGBA image, with tiff_lzw compression. Pillow 4.3.0 added support for the 16 bit RGBA type, though the output image is a lower precision 8 bit per channel RGBA image. Prior to that, there was no support for this image.

    Pillow (and PIL before it) have had internal support for tiff_lzw compression, but apparently it's either buggy or cannot handle this particular image mode.

    Forcing the TiffImagePlugin to use the libtiff decoder allows Pillow to properly decode this image.

  3. changed the title [-]TIFF that could not be loaded in 4.2.1 gets silently corrupted in 4.3.0[/-] [+]TIFF_LZW decompression is incorrect for 16bpc image[/+] on Nov 11, 2017
  4. added
    Bug
    on Nov 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPNGTIFF

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions