Opened 18 years ago
Closed 17 years ago
#4478 closed (fixed)
[patch] PIL Bug Causes Django 0.96 Image Validator to Break if OLE Document Uploaded
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Validators | Version: | 0.96 |
Severity: | Keywords: | image validator | |
Cc: | v.oostveen@… | Triage Stage: | Design decision needed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
My first test was to upload a valid image. Worked fine.
My next few tests were to upload invalid files: pdf, vb, xml, txt,
etc.
The result was a nice error message except when I tried to upload any
kind of MS Office file. This broke Django...
Traceback (most recent call last):
File "C:\Python24\Lib\site-packages\django\core\handlers\base.py" in
get_response
- response = callback(request, *callback_args, callback_kwargs)
File "C:\Python24\Lib\site-packages\django\contrib\auth\decorators.py"
in _checklogin
- return view_func(request, *args, kwargs)
File "c:\idms_project\idms\ssi\views.py" in update_ssi_status
- errors = manipulator.get_validation_errors(new_data)
File "C:\Python24\Lib\site-packages\django\oldforms\init.py" in
get_validation_errors
- errors.update(field.get_validation_errors(new_data))
File "C:\Python24\Lib\site-packages\django\oldforms\init.py" in
get_validation_errors
- self.run_validator(new_data, validator)
File "C:\Python24\Lib\site-packages\django\oldforms\init.py" in
run_validator
- validator(new_data.get(self.field_name, ), new_data)
File "C:\Python24\Lib\site-packages\django\oldforms\init.py" in
isValidImage
- validators.isValidImage(field_data, all_data)
File "C:\Python24\Lib\site-packages\django\core\validators.py" in
isValidImage
- Image.open(StringIO(content))
File "C:\Python24\lib\site-packages\PIL\Image.py" in open
- return factory(fp, filename)
File "C:\Python24\lib\site-packages\PIL\ImageFile.py" in init
- self._open()
File "C:\Python24\lib\site-packages\PIL\FpxImagePlugin.py" in _open
- self.ole = OleFileIO(self.fp)
File "C:\Python24\lib\site-packages\PIL\OleFileIO.py" in init
- self.open(filename)
File "C:\Python24\lib\site-packages\PIL\OleFileIO.py" in open
- self.loadfat(header)
File "C:\Python24\lib\site-packages\PIL\OleFileIO.py" in loadfat
- s = self.getsect(ix)
File "C:\Python24\lib\site-packages\PIL\OleFileIO.py" in getsect
- self.fp.seek(512 + self.sectorsize * sect)
OverflowError at /ssi/ssi_status/update/380/181/
long int too large to convert to int
According to Chris Beaven, the problem is with PIL...
-quote-
It's a bug with PIL reading OLE files with Python 2.4:
http://mail.python.org/pipermail/image-sig/2006-February/003764.html
Probably worth filing a ticket - it'd be easy enough to catch
OverflowError in our validator.
-end quote-
Attachments (1)
Change History (5)
comment:1 by , 18 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
by , 18 years ago
Attachment: | pil_validator_fix.patch added |
---|
comment:2 by , 18 years ago
Cc: | added |
---|---|
Has patch: | set |
Summary: | PIL Bug Causes Django 0.96 Image Validator to Break if OLE Document Uploaded → [patch] PIL Bug Causes Django 0.96 Image Validator to Break if OLE Document Uploaded |
Applyed this patch to my django project and it works fine.
I'm +1 on including this
only recommand that we change the except to:
except (IOError, OverflowError): # Python Imaging Library doesn't recognize it as an image
so it's less confusing towards except Exception, e: and future Python versions.
p.s. i don't think this is a design decision, this is a bug in PIL and we should capture the OverFlow acception.
as it tells the application, something went wrong in trying to read the image (OLE object in this case)
comment:4 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Design decision because I'm not sure what the policy is on Django working around bugs in third-party products. I do have a simple patch which will solve the problem if we do want to work around it.