Skip to content

Using ImageFile.Parser() gets an OSError when reading an in-spec WebP image #2795

Closed

Description

@alexwlchan

This was originally spotted while debugging failing tests in loris-imageserver/loris#364.

What did you do?

Load a valid WEBP image by using ImageFile.Parser. I expect the Parser to read the image without raising an exception – instead, it raises an IOError "image was incomplete".

What versions of Pillow and Python are you using?

I can reproduce the issue with Pythons 2.7.13 and 3.6.1, in both cases with Pillow 4.3.0:

$ pip freeze
olefile==0.44
Pillow==4.3.0

Sample reproduction

I'm using a sample image 1.webp, downloaded from Google’s WebP gallery. A copy is also attached to the issue (compressed, because GitHub doesn't support WebP).

By my reckoning, this is an in-spec WebP image:

$ identify 1.webp
Decoded /var/folders/jy/351n9lnj5l3f07rtf2xybxx00000gn/T/magick-223024t3-o47WaC8o. Dimensions: 550 x 368 . Format: lossy. Now saving...
Saved file /var/folders/jy/351n9lnj5l3f07rtf2xybxx00000gn/T/magick-22302pw3OQD5DHOLd
1.webp PAM 550x368 550x368+0+0 8-bit TrueColor sRGB 810KB 0.000u 0:00.009

$ shasum 1.webp
0c03dcd19f804a559bd0ae32db2998dad4a4936a  1.webp

The following code reliably triggers the error:

#!/usr/bin/env python
# -*- encoding: utf-8

from PIL.ImageFile import Parser

p = Parser()
p.feed(open('1.webp', 'rb').read())
p.close()

with the following traceback:

Traceback (most recent call last):
  File "pillow_webp.py", line 8, in <module>
    p.close()
  File "/Users/alexwlchan/.virtualenvs/tempenv-2005296845a12/lib/python3.6/site-packages/PIL/ImageFile.py", line 438, in close
    raise IOError("image was incomplete")
OSError: image was incomplete

The following code does not trigger an error, but proves that Pillow is capable of processing the image correctly, as it produces a valid JPEG which matches Google’s test image:

#!/usr/bin/env python
# -*- encoding: utf-8

from PIL import Image

im = Image.open('1.webp')
im.save('1.jpg')

The issue was originally spotted with a WebP image that Pillow itself had created – a source JPEG image was being saved as WebP, then re-fed to Parser(). I can elaborate if it's useful, but that could go wrong if Pillow crashes in the Parser or if Pillow is writing bad WebP images – and I prefer the repro with Google's test image, because I think it rules out the latter.

Attachments

1.webp.zip

Activity

  1. alexwlchan commented on Oct 8, 2017

    @alexwlchan
    ContributorAuthor

    Ah, so it looks like WebP just doesn’t have any incremental decoding support – if I clone #1122 and test locally, I don’t get this error. So looks like the fix is somewhere in there, albeit stalled.

  2. hugovk commented on Oct 8, 2017

    @hugovk
    Member

    How about with PR #2761?

  3. alexwlchan commented on Oct 8, 2017

    @alexwlchan
    ContributorAuthor

    How about with PR #2761?

    Yep, I also get no errors with that.

  4. hugovk commented on Oct 8, 2017

    @hugovk
    Member

    Great, hopefully one or both of those will be in the next quarterly release.

  5. radarhere commented on Aug 11, 2018

    @radarhere
    Member

    Closing, after the merge of the relevant PR. Please reopen if this is not resolved.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions