From 7115465afa549955ec446638e0d73b597e6ffd20 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 11 Sep 2007 13:13:35 +0000 Subject: [PATCH] Fixed #4478 -- Added a catch for an error thrown by PIL when attempting to validate MS OLE files. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6096 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/validators.py | 4 +++- django/newforms/fields.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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