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

Fails with PIL on uncomplete exif jpeg #98

Closed
hynekcer opened this Issue Apr 11, 2012 · 7 comments

Comments

Projects
None yet
6 participants
@hynekcer

hynekcer commented Apr 11, 2012

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

This comment has been minimized.

Show comment
Hide comment
@hynekcer

hynekcer Apr 11, 2012

I am sorry. It should be

except (AttributeError, KeyError):

hynekcer commented Apr 11, 2012

I am sorry. It should be

except (AttributeError, KeyError):

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Apr 18, 2012

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):

ghost commented Apr 18, 2012

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

This comment has been minimized.

Show comment
Hide comment
@hynekcer

hynekcer Apr 18, 2012

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

hynekcer commented Apr 18, 2012

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

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Apr 18, 2012

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.

ghost commented Apr 18, 2012

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.

@ksysctl

This comment has been minimized.

Show comment
Hide comment
@ksysctl

ksysctl Apr 27, 2012

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

except (AttributeError, KeyError, IndexError):

it resolved that issue.

ksysctl commented Apr 27, 2012

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

This comment has been minimized.

Show comment
Hide comment
@gregplaysguitar

gregplaysguitar May 20, 2012

Contributor

I'm getting this error too -

except (AttributeError, KeyError, IndexError):

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

Contributor

gregplaysguitar commented May 20, 2012

I'm getting this error too -

except (AttributeError, KeyError, IndexError):

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

@linus

This comment has been minimized.

Show comment
Hide comment
@linus

linus Aug 15, 2012

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

linus commented Aug 15, 2012

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 added a commit to onjin/sorl-thumbnail that referenced this issue Jan 27, 2013

herrobenny added a commit to herrobenny/sorl-thumbnail that referenced this issue May 3, 2013

philipn added a commit to philipn/sorl-thumbnail that referenced this issue Jun 28, 2013

@tclancy

This comment has been minimized.

Show comment
Hide comment
@tclancy

tclancy Aug 20, 2013

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

tclancy commented Aug 20, 2013

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 added a commit to rmaceissoft/sorl-thumbnail that referenced this issue Oct 25, 2013

@ghost ghost assigned mariocesar Nov 12, 2013

@mariocesar

This comment has been minimized.

Show comment
Hide comment
@mariocesar

mariocesar Dec 19, 2013

Collaborator

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

Collaborator

mariocesar commented Dec 19, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment