Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29705 closed Bug (fixed)

RuntimeError while saving webp file to ImageField

Reported by: Ji Qu Owned by: Ji Qu
Component: Core (Other) Version: dev
Severity: Normal Keywords: image get_image_dimensions
Cc: Ji Qu Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ji Qu)

Hi,

This is my first time to report a bug for django-project, please feel free to give me a hand if I have any non-standard workflow.

I have meet a "RuntimError" while trying to save a webp-image.

I have searched django tickets with following link but no similar ticket found:

search result

I have made a online project to reproduce the "bug".

Please follow this link to track how this bug happens and how it affects my own sites.

A patch is being making to fix the possible "RuntimeError" while saving a webp page.

For your information, I will also paste the code which could reproduce the bug.

import os

from django.core.files.images import get_image_dimensions
import pytest


FILE_NAME = 'img.webp'

here = os.path.dirname(__file__)
file_path = os.path.join(here, FILE_NAME)


def test_webp_parse_error():
    """
    Webp file from douban.com, displays in browser well,
    can be opened by PIL but error occurs while use django parse.
    """
    with pytest.raises(
        RuntimeError,
    ) as info:
        with open(file_path, 'rb') as fp:
            get_image_dimensions(file_or_path=fp, close=True)
    assert str(info.value) == 'could not create decoder object'


def test_the_working_way():
    with open(file_path, "rb") as fp:
        from PIL import Image
        image = Image.open(fp)
        print(image.size)

Please download the image with these links:
From douban: https://img3.doubanio.com/view/status/m/public/a606779b213ae14.webp
From google: https://developers.google.com/speed/webp/gallery?hl=zh-CN
https://www.gstatic.com/webp/gallery/4.sm.webp

Python version:

Python 3.6.4

Kernel version:

Linux ubuntu 4.15.0-29-generic #31~16.04.1-Ubuntu SMP Wed Jul 18 08:54:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Version of libweb:

ii libwebp-dev:amd64 0.4.4-1 amd64 Lossy compression of digital photographic images.
ii libwebp5:amd64 0.4.4-1 amd64 Lossy compression of digital photographic images.
ii libwebpdemux1:amd64 0.4.4-1 amd64 Lossy compression of digital photographic images.
ii libwebpmux1:amd64 0.4.4-1 amd64 Lossy compression of digital photographic images.

When the error occurs:

While I try to save image with webp format, the error occurs.

Change History (8)

comment:1 by Ji Qu, 6 years ago

Owner: changed from nobody to Ji Qu
Status: newassigned

comment:2 by Ji Qu, 6 years ago

Keywords: get_image_dimensions added; get removed

comment:3 by Ji Qu, 6 years ago

Description: modified (diff)
Summary: Runtimeerror while Django Image Field received some type of webp fileRuntimeError while save webp file to Image-Field

comment:4 by Ji Qu, 6 years ago

Summary: RuntimeError while save webp file to Image-FieldRuntimeError while saving webp file to Image-Field

comment:5 by Ji Qu, 6 years ago

Cc: Ji Qu added
Has patch: set

comment:6 by Carlton Gibson, 6 years ago

Triage Stage: UnreviewedAccepted

Hi Ji Qu.

Thanks for the report. Very well put together.

Looks reasonable.

comment:7 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In c69d40f:

Fixed #29705 -- Fixed ImageField RuntimeError crash for WebP files.

comment:8 by Tim Graham, 6 years ago

Summary: RuntimeError while saving webp file to Image-FieldRuntimeError while saving webp file to ImageField
Note: See TracTickets for help on using tickets.
Back to Top