Ticket #30252: 0002-Fixed-30252-Reopen-uploaded-image-after-verify.patch

File 0002-Fixed-30252-Reopen-uploaded-image-after-verify.patch, 1.1 KB (added by Felix Dreissig, 5 years ago)

Patch containing a possible fix

  • django/forms/fields.py

    From a456e2d2cb8728764b9726290100ba6b8744702e Mon Sep 17 00:00:00 2001
    From: Felix Dreissig <f30@f30.me>
    Date: Tue, 26 Mar 2019 12:55:00 +0100
    Subject: [PATCH 2/2] Fixed #30252 -- Reopen uploaded image after verify()
    
    According to the Pillow docs, "you must reopen the image file" if you
    want to use it after calling verify().
    ---
     django/forms/fields.py | 3 ++-
     1 file changed, 2 insertions(+), 1 deletion(-)
    
    diff --git a/django/forms/fields.py b/django/forms/fields.py
    index a977256525..7aef2ae91e 100644
    a b class ImageField(FileField):  
    631631            image.verify()
    632632
    633633            # Annotating so subclasses can reuse it for their own validation
    634             f.image = image
     634            # The original `image` is not usable anymore after calling verify()
     635            f.image = Image.open(file)
    635636            # Pillow doesn't detect the MIME type of all formats. In those
    636637            # cases, content_type will be None.
    637638            f.content_type = Image.MIME.get(image.format)
Back to Top