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
This commit is contained in:
parent
2cf419d9ed
commit
7115465afa
|
@ -182,7 +182,9 @@ def isValidImage(field_data, all_data):
|
||||||
raise ValidationError, _("No file was submitted. Check the encoding type on the form.")
|
raise ValidationError, _("No file was submitted. Check the encoding type on the form.")
|
||||||
try:
|
try:
|
||||||
Image.open(StringIO(content))
|
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.")
|
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):
|
def isValidImageURL(field_data, all_data):
|
||||||
|
|
|
@ -393,7 +393,9 @@ class ImageField(FileField):
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
try:
|
try:
|
||||||
Image.open(StringIO(f.content))
|
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."))
|
raise ValidationError(ugettext(u"Upload a valid image. The file you uploaded was either not an image or a corrupted image."))
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue