dedup.image: img.convert can also raise that crazy stuff
authorHelmut Grohne <helmut@subdivi.de>
Mon, 27 May 2013 09:59:33 +0000 (11:59 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Mon, 27 May 2013 09:59:33 +0000 (11:59 +0200)
dedup/image.py

index acbf0ca..1148890 100644 (file)
@@ -62,7 +62,10 @@ class ImageHash(object):
             elif img.mode == "RGB":
                 pack = lambda elem: struct.pack("BBBB", *(elem + (255,)))
             elif img.mode != "RGBA":
             elif img.mode == "RGB":
                 pack = lambda elem: struct.pack("BBBB", *(elem + (255,)))
             elif img.mode != "RGBA":
-                img = img.convert("RGBA")
+                try:
+                    img = img.convert("RGBA")
+                except (SyntaxError, IndexError, IOError): # crazy stuff from PIL
+                    raise ValueError("error reading png image")
             try:
                 for elem in img.getdata():
                     hashobj.update(pack(elem))
             try:
                 for elem in img.getdata():
                     hashobj.update(pack(elem))