diff --git a/django/core/validators.py b/django/core/validators.py index bdcf39e3aa..fd28ba4ef8 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -182,7 +182,9 @@ def isValidImage(field_data, all_data): raise ValidationError, _("No file was submitted. Check the encoding type on the form.") try: Image.open(StringIO(content)) - except IOError: # Python Imaging Library doesn't recognize it as an image + except (IOError, OverflowError): # Python Imaging Library doesn't recognize it as an image + # OverflowError is due to a bug in PIL with Python 2.4+ which can cause + # it to gag on OLE files. raise ValidationError, _("Upload a valid image. The file you uploaded was either not an image or a corrupted image.") def isValidImageURL(field_data, all_data): diff --git a/django/newforms/fields.py b/django/newforms/fields.py index 658eea6fba..a98779a334 100644 --- a/django/newforms/fields.py +++ b/django/newforms/fields.py @@ -393,7 +393,9 @@ class ImageField(FileField): from cStringIO import StringIO try: Image.open(StringIO(f.content)) - except IOError: # Python Imaging Library doesn't recognize it as an image + except (IOError, OverflowError): # Python Imaging Library doesn't recognize it as an image + # OverflowError is due to a bug in PIL with Python 2.4+ which can cause + # it to gag on OLE files. raise ValidationError(ugettext(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image.")) return f