#19457 closed Bug (fixed)
ImageField size detection fails for some files even when PIL could succeed
Reported by: | Stephen Burrows | Owned by: | Anton Baklanov |
---|---|---|---|
Component: | File uploads/storage | Version: | 1.4 |
Severity: | Normal | Keywords: | image |
Cc: | antonbaklanov@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Some PNG files can't have their size detected by django because the clever method of size detection Django employs (I suspect in order to be somewhat more efficient?) fails horribly in these cases.
>>> import Image >>> with open('/path/to/file.png') as f: ... im = Image.open(f) ... >>> im.size (480, 362) >>> from django.core.files.images import get_image_dimensions >>> with open('/path/to/file.png') as f: ... get_image_dimensions(f) ... Traceback (most recent call last): File "<console>", line 2, in <module> File "django/core/files/images.py", line 58, in get_image_dimensions p.feed(data) File "PIL/ImageFile.py", line 402, in feed im = Image.open(fp) File "PIL/Image.py", line 1965, in open return factory(fp, filename) File "PIL/ImageFile.py", line 91, in __init__ self._open() File "PIL/PngImagePlugin.py", line 331, in _open s = self.png.call(cid, pos, len) File "PIL/PngImagePlugin.py", line 115, in call return getattr(self, "chunk_" + cid)(pos, len) File "PIL/PngImagePlugin.py", line 296, in chunk_zTXt self.im_info[k] = self.im_text[k] = zlib.decompress(v[1:]) error: Error -5 while decompressing data: incomplete or truncated stream
Change History (7)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
failing test
i've used your png example there
comment:3 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
this is 'fixing' problem:
@@ -50,7 +50,7 @@ def get_image_dimensions(file_or_path, close=False): # Most of the time PIL only needs a small chunk to parse the image and # get the dimensions, but with some TIFF files PIL needs to parse the # whole file. - chunk_size = 1024 + chunk_size = 2048 while 1: data = file.read(chunk_size) if not data:
i will try to dig into that and find more robust solution.
comment:4 by , 12 years ago
Has patch: | set |
---|
maybe we also need to contact with PIL guys, because Parser.feed()
does not supposed to raise zlib.error
in case like our, it must silently wait for more data
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
I can't attach the file that I'm using for testing, since it's too big (276kb), but you can download it (at least for now) here: http://s3.mirocommunity.org.s3.amazonaws.com/tyhychi/localtv/video_thumbs/43/orig.png