#11840 closed (worksforme)
Form validation should check for IOErrors
Reported by: | Stavros Korokithakis | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.1 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Forms currently break on various types of images when PIL raises an IOError exception. This should be handled as a form error instead of crashing Django. A traceback is below:
File "main/views.py", line 244, in ad_create_category
if form.is_valid() and image_formset.is_valid():
File "lib/python2.6/site-packages/django/forms/formsets.py", line 237, in is_valid
if bool(self.errors[i]):
File "lib/python2.6/site-packages/django/forms/formsets.py", line 211, in _get_errors
self.full_clean()
File "lib/python2.6/site-packages/django/forms/formsets.py", line 250, in full_clean
self._errors.append(form.errors)
File "lib/python2.6/site-packages/django/forms/forms.py", line 111, in _get_errors
self.full_clean()
File "lib/python2.6/site-packages/django/forms/forms.py", line 238, in full_clean
value = field.clean(value, initial)
File "lib/python2.6/site-packages/django/forms/fields.py", line 511, in clean
trial_image.load()
File "lib/python2.6/site-packages/PIL/ImageFile.py", line 155, in load
self.load_prepare()
File "lib/python2.6/site-packages/PIL/PngImagePlugin.py", line 337, in load_prepare
raise IOError("cannot read interlaced PNG files")
Change History (4)
comment:1 by , 15 years ago
Component: | Uncategorized → Forms |
---|---|
Needs tests: | set |
Resolution: | → worksforme |
Status: | new → closed |
comment:2 by , 15 years ago
Sadly, I've searched high and low for such a file, but none of my users has responded. Looking at your code it is indeed miraculous that this happens, but looking at mine elucidates the situation:
def clean(self, data, initial=None): ... # load() is the only method that can spot a truncated JPEG, # but it cannot be called sanely after verify() trial_image = Image.open(file) trial_image.load()
There's no exception block to be found there. I assume it was added after 1.1?
comment:3 by , 15 years ago
No, the try: except: block is present in the 1.1 tarball, just checked just to be sure.
comment:4 by , 15 years ago
That's odd, I checked my home install and it has it, but both production and staging don't, and django.VERSION reports 1.1.0 there. This is positively strange, but I upgraded and everything is fine now, thank you.
can you provide a test for that? or just a file that results in this error? Looking through the code that shouldn't happen:
I am closing it as works for me, feel free to reopen it if you find a file that results in this error. Thanks!