Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fails with PIL on uncomplete exif jpeg #98

Closed
hynekcer opened this Issue · 7 comments

6 participants

@hynekcer

Sorl-thumbnail 11 fails in this image file
https://bitbucket.org/chris1610/satchmo/raw/60e0513633ad/satchmo/static/images/productimage-picture-default.jpg
with PIL 1.1.6-3.
because it has empty exif.

Traceback
/home/me/lib/python2.5/sorl/thumbnail/engines/pil_engine.py 29 in _orientation
exif = image._getexif()
/usr/lib/python2.5/site-packages/PIL/JpegImagePlugin.py 354 in _getexif
file.seek(exif[0x8769])
Exception Type: TemplateSyntaxError
Exception Value: Caught KeyError while rendering: 34665

Patch:

diff -u a/sorl/thumbnail/engines/pil_engine.py b/sorl/thumbnail/engines/pil_engine.py
--- a/sorl/thumbnail/engines/pil_engine.py
+++ b/sorl/thumbnail/engines/pil_engine.py
@@ -27,7 +27,7 @@
def _orientation(self, image):
try:
exif = image._getexif()

  • except AttributeError:
  • except AttributeError, KeyError: exif = None if exif: orientation = exif.get(0x0112)
@hynekcer

I am sorry. It should be

except (AttributeError, KeyError):

@ghost

I'm also getting an IndexError on a png Image with latest PIL v1.1.7. So I guess the except clause should be modified:

except (AttributeError, KeyError, IndexError):

@hynekcer

It looks reasonable. Can you send a link to such png image?

@ghost

This is the image link (It is in fact a jpg image, not a png)

http://static.punterslobby.com/media/images/news/full/160993.jpg

Can you reproduce this? Simply catching the exception worked for me.

@gin

I can confirm this issue on sorl-thumbnail version: 11.12 and when I it catches:

except (AttributeError, KeyError, IndexError):

it resolved that issue.

@gregplaysguitar

I'm getting this error too -

except (AttributeError, KeyError, IndexError):

fixed it for me. Definitely needs to be merged into master!

@linus

Unfortunately, it seems _getexif() can also give you an IOError.

This image gives me an IOError when calling get_thumbnail (or Image.open('file')._getexif()):

http://apprl.com/media/static/products/mango/1__73650255__73650255_94.jpg

See also http://stackoverflow.com/questions/10583265/python-image-library-error-caught-ioerror-while-rendering-not-enough-data

@onjin onjin referenced this issue from a commit in onjin/sorl-thumbnail
@onjin onjin Fixing #98 and #99 - problems with exif on some images b43e2f6
@herrobenny herrobenny referenced this issue from a commit in herrobenny/sorl-thumbnail
@herrobenny herrobenny fixed #98 and #99 - problems with exif on some images f1f752f
@philipn philipn referenced this issue from a commit in philipn/sorl-thumbnail
@philipn philipn Fix for #98. bdc325a
@tclancy

Applying the fix to _getexif() results in an error in get_image()

return Image.open(buf)
File "python2.7/site-packages/PIL/Image.py", line 1980, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file
@rmaceissoft rmaceissoft referenced this issue from a commit in rmaceissoft/sorl-thumbnail
@rmaceissoft rmaceissoft fixed #98 and #99 - problems with exif on some images ebb179a
@mariocesar mariocesar was assigned
@mariocesar
Owner

A fix has been merged into the master branch, please reopen this issue if it persists

https://github.com/mariocesar/sorl-thumbnail/blob/master/sorl/thumbnail/engines/pil_engine.py#L65

@mariocesar mariocesar closed this
@scottmx81 scottmx81 referenced this issue in suicidegirlsdev/sorl-thumbnail
Merged

Ignore EXIF exceptions #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.