Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.4.x] Fixed second security issue in image uploading. Disclosure an…

…d release forthcoming.

Backport of b1d4634 from master.
  • Loading branch information...
commit c14f325c4eef628bc7bfd8873c3a72aeb0219141 1 parent da33d67
Florian Apolloner authored July 30, 2012

Showing 1 changed file with 4 additions and 14 deletions. Show diff stats Hide diff stats

  1. 18  django/forms/fields.py
18  django/forms/fields.py
@@ -570,20 +570,10 @@ def to_python(self, data):
570 570
                 file = StringIO(data['content'])
571 571
 
572 572
         try:
573  
-            # load() is the only method that can spot a truncated JPEG,
574  
-            #  but it cannot be called sanely after verify()
575  
-            trial_image = Image.open(file)
576  
-            trial_image.load()
577  
-
578  
-            # Since we're about to use the file again we have to reset the
579  
-            # file object if possible.
580  
-            if hasattr(file, 'reset'):
581  
-                file.reset()
582  
-
583  
-            # verify() is the only method that can spot a corrupt PNG,
584  
-            #  but it must be called immediately after the constructor
585  
-            trial_image = Image.open(file)
586  
-            trial_image.verify()
  573
+            # load() could spot a truncated JPEG, but it loads the entire
  574
+            # image in memory, which is a DoS vector. See #3848 and #18520.
  575
+            # verify() must be called immediately after the constructor.
  576
+            Image.open(file).verify()
587 577
         except ImportError:
588 578
             # Under PyPy, it is possible to import PIL. However, the underlying
589 579
             # _imaging C module isn't available, so an ImportError will be

0 notes on commit c14f325

Please sign in to comment.
Something went wrong with that request. Please try again.