Skip to content

Commit

Permalink
Fixed a security issue in image uploading. Disclosure and release for…
Browse files Browse the repository at this point in the history
…thcoming.
  • Loading branch information
apollo13 committed Jul 30, 2012
1 parent e567f43 commit dd16b17
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion django/core/files/images.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ def get_image_dimensions(file_or_path, close=False):
file = open(file_or_path, 'rb') file = open(file_or_path, 'rb')
close = True close = True
try: try:
# 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
while 1: while 1:
data = file.read(1024) data = file.read(chunk_size)
if not data: if not data:
break break
p.feed(data) p.feed(data)
if p.image: if p.image:
return p.image.size return p.image.size
chunk_size = chunk_size*2
return None return None
finally: finally:
if close: if close:
Expand Down

0 comments on commit dd16b17

Please sign in to comment.