Uncaught division by zero error on some GIFs #163

scottjacobsen opened this Issue Feb 7, 2013 · 4 comments


None yet

3 participants


Thumbor is crashing for me on some GIF images with a division by zero error.

Here's one example that causes the crash for me:

ERROR:root:Uncaught exception GET /4tpNAcnSqRkmRULuJ2yNI9wAnMY=/http://media.nola.com/design/alpha
/img/logo_nola.gif (
HTTPRequest(protocol='http', host='localhost:8888', method='GET', uri='/4tpNAcnSqRkmRULuJ2yNI9wAnM
Y=/http://media.nola.com/design/alpha/img/logo_nola.gif', version='HTTP/1.1', remote_ip='
', body='', headers={'Via': '1.1 061d744bbab4ac65ac8fd38b49f80f61.cloudfront.net (CloudFront)', 'A
ccept-Encoding': 'gzip', 'X-Forwarded-Host': 'nassets.neighborland.com', 'X-Forwarded-For': '98.24
5.120.33,', 'Host': 'localhost:8888', 'User-Agent': 'Amazon CloudFront', 'Connection': '
Keep-Alive', 'X-Amz-Cf-Id': 'SKEiyx-9k0R6-05_xcwWIcptdSRsKWA9yCfZ3StJIwKaqY8fIfZ75Q==', 'Cache-Con
trol': 'max-age=86400', 'X-Forwarded-Server': 'next.neighborland.com'})
Traceback (most recent call last):
  File "/home/neighborland/thumbor/local/lib/python2.7/site-packages/tornado/web.py", line 1040, i
n wrapper
    return method(self, *args, **kwargs)
  File "/home/neighborland/thumbor/local/lib/python2.7/site-packages/thumbor/handlers/imaging.py",
 line 85, in get
    return self.execute_image_operations()
  File "/home/neighborland/thumbor/local/lib/python2.7/site-packages/thumbor/handlers/__init__.py"
, line 71, in execute_image_operations
  File "/home/neighborland/thumbor/local/lib/python2.7/site-packages/thumbor/handlers/__init__.py"
, line 125, in get_image
    self._fetch(self.context.request.image_url, self.context.request.extension, callback)
  File "/home/neighborland/thumbor/local/lib/python2.7/site-packages/thumbor/handlers/__init__.py"
, line 208, in _fetch
    callback(False, buffer=buffer)
  File "/home/neighborland/thumbor/local/lib/python2.7/site-packages/thumbor/handlers/__init__.py"
, line 121, in callback
  File "/home/neighborland/thumbor/local/lib/python2.7/site-packages/thumbor/transformer.py", line
 87, in transform
  File "/home/neighborland/thumbor/local/lib/python2.7/site-packages/thumbor/transformer.py", line
 143, in smart_detect
  File "/home/neighborland/thumbor/local/lib/python2.7/site-packages/thumbor/transformer.py", line
 168, in after_smart_detect
  File "/home/neighborland/thumbor/local/lib/python2.7/site-packages/thumbor/transformer.py", line
 196, in auto_crop
    source_ratio = round(float(source_width) / source_height, 2)
ZeroDivisionError: float division by zero

I've noticed this happens with the graphicsMagick driver, but not the PIP driver.


After trying hard to understand what's going on, I'm at a loss. Apparently I can't read any gifs using GraphicsMagick if reading from a Blob. The code we are using to read is the following:

    blob = Blob(buffer)
    img = Image(blob)

After the above if I try img.isValid() it returns false!!! It works with PNGs and JPEGs. I'm not sure how to move forward on this issue. Haven't found anything on the web that helps in understanding what's going on.

For now, I'll put a remark in the front page of the documentation saying that GraphicsMagick engine does not support gif images. I'm not happy about it, though 👎 👎 👎

I have tried to reproduce the issue, and it seems to work for me.
However, I did not run it inside thumbor. I compiled GraphicsMagick and tested the GIF with pgmagic following the same pattern thumbor does (I guess).

I did the following script to test it:

from pgmagick import Image, Blob
im = Image('logo_nola.gif')
buffer = open('logo_nola.gif').read()
im2 = Image(Blob(buffer))

Both gif images are identical.

My environment was a Ubuntu 12.04 running in a VirtualBox VM on top of MacOSX Maverick.
GraphicsMagick 1.3.19 was configured with :
-fopenmp -g -O2 -Wall -pthread
-lGraphicsMagick -llcms2 -ltiff -lfreetype -ljasper -ljpeg -lpng12 -llzma -lxml2 -lz -lm -lgomp -lpthread
rodsenra@rodsenra-VirtualBox:/usr/local/src$ /usr/local/bin/GraphicsMagick-config --version

I would like to help solve this issue. Please verify with the issue still holds after upgrading thumbor to GraphicsMagick 1.3.19 and pgmagick changeset: 295:2bead512c119

It is working with animated gifs also. I tried with https://marligo.files.wordpress.com/2013/06/animated_fire.gif?w=450 and it worked like a charm.

@heynemann heynemann closed this in 2f4aadd Mar 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment