diff options
| author | Florian Apolloner <florian@apolloner.eu> | 2012-07-30 21:57:22 +0200 |
|---|---|---|
| committer | Florian Apolloner <florian@apolloner.eu> | 2012-07-30 21:57:22 +0200 |
| commit | b1d463468694f2e91fde67221b7996e9c52a9720 (patch) | |
| tree | 47de58405e17de69306374bacb2436512212a593 | |
| parent | dd16b17099b7d86f27773df048c5014cf439b282 (diff) | |
Fixed second security issue in image uploading. Disclosure and release forthcoming.
| -rw-r--r-- | django/forms/fields.py | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index c4a675da74..cdb1d7be67 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -560,20 +560,10 @@ class ImageField(FileField): file = BytesIO(data['content']) try: - # load() is the only method that can spot a truncated JPEG, - # but it cannot be called sanely after verify() - trial_image = Image.open(file) - trial_image.load() - - # 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() + # load() could spot a truncated JPEG, but it loads the entire + # image in memory, which is a DoS vector. See #3848 and #18520. + # verify() must be called immediately after the constructor. + Image.open(file).verify() except ImportError: # Under PyPy, it is possible to import PIL. However, the underlying # _imaging C module isn't available, so an ImportError will be |
