Skip to content

Commit

Permalink
[1.3.x] Fixed second security issue in image uploading. Disclosure an…
Browse files Browse the repository at this point in the history
…d release forthcoming.

Backport of b1d4634 from master.
  • Loading branch information
apollo13 committed Jul 30, 2012
1 parent 9ca0ff6 commit b2eb478
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions django/forms/fields.py
Expand Up @@ -538,20 +538,10 @@ def to_python(self, data):
file = StringIO(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, 'reset'):
file.reset()

# 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
Expand Down

0 comments on commit b2eb478

Please sign in to comment.