Skip to content

Commit 9ca0ff6

Browse files
committed
[1.3.x] Fixed a security issue in image uploading. Disclosure and release forthcoming.
Backport of dd16b17 from master.
1 parent 7ca10b1 commit 9ca0ff6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

django/core/files/images.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,18 @@ def get_image_dimensions(file_or_path, close=False):
4747
file = open(file_or_path, 'rb')
4848
close = True
4949
try:
50+
# Most of the time PIL only needs a small chunk to parse the image and
51+
# get the dimensions, but with some TIFF files PIL needs to parse the
52+
# whole file.
53+
chunk_size = 1024
5054
while 1:
51-
data = file.read(1024)
55+
data = file.read(chunk_size)
5256
if not data:
5357
break
5458
p.feed(data)
5559
if p.image:
5660
return p.image.size
61+
chunk_size = chunk_size*2
5762
return None
5863
finally:
5964
if close:

0 commit comments

Comments
 (0)