1
0
mirror of https://github.com/django/django.git synced 2025-01-31 20:59:17 +00:00

Fixed second security issue in image uploading. Disclosure and release forthcoming.

This commit is contained in:
Florian Apolloner 2012-07-30 21:57:22 +02:00
parent dd16b17099
commit b1d4634686

View File

@ -560,20 +560,10 @@ class ImageField(FileField):
file = BytesIO(data['content']) file = BytesIO(data['content'])
try: try:
# load() is the only method that can spot a truncated JPEG, # load() could spot a truncated JPEG, but it loads the entire
# but it cannot be called sanely after verify() # image in memory, which is a DoS vector. See #3848 and #18520.
trial_image = Image.open(file) # verify() must be called immediately after the constructor.
trial_image.load() Image.open(file).verify()
# Since we're about to use the file again we have to reset the
# file object if possible.
if hasattr(file, 'seek') and callable(file.seek):
file.seek(0)
# verify() is the only method that can spot a corrupt PNG,
# but it must be called immediately after the constructor
trial_image = Image.open(file)
trial_image.verify()
except ImportError: except ImportError:
# Under PyPy, it is possible to import PIL. However, the underlying # Under PyPy, it is possible to import PIL. However, the underlying
# _imaging C module isn't available, so an ImportError will be # _imaging C module isn't available, so an ImportError will be