mirror of
https://github.com/django/django.git
synced 2025-10-29 16:46:11 +00:00
Fixed #23103 -- Annotated ImageField file with image and content_type attributes.
Thanks Jeremy Dunck for the suggestion and Nick Sanford for review.
This commit is contained in:
committed by
Tim Graham
parent
8c2b405ba8
commit
8b7347220f
@@ -659,8 +659,13 @@ class ImageField(FileField):
|
||||
try:
|
||||
# load() could spot a truncated JPEG, but it loads the entire
|
||||
# image in memory, which is a DoS vector. See #3848 and #18520.
|
||||
image = Image.open(file)
|
||||
# verify() must be called immediately after the constructor.
|
||||
Image.open(file).verify()
|
||||
image.verify()
|
||||
|
||||
# Annotating so subclasses can reuse it for their own validation
|
||||
f.image = image
|
||||
f.content_type = Image.MIME[image.format]
|
||||
except Exception:
|
||||
# Pillow doesn't recognize it as an image.
|
||||
six.reraise(ValidationError, ValidationError(
|
||||
|
||||
Reference in New Issue
Block a user