summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwinkidney <winkidney@gmail.com>2018-08-22 19:34:51 +0800
committerTim Graham <timograham@gmail.com>2018-08-23 09:04:25 -0400
commitc69d40f94308d52243133def3b6be7ff403df6f1 (patch)
tree4e589d7e17d61345917daaab8fc102aa90c4db53
parent586a9dc4295357de1f5ad0590ad34bf2bc008f79 (diff)
Fixed #29705 -- Fixed ImageField RuntimeError crash for WebP files.
-rw-r--r--django/core/files/images.py4
-rw-r--r--tests/files/test.webpbin0 -> 26390 bytes
-rw-r--r--tests/files/tests.py6
3 files changed, 10 insertions, 0 deletions
diff --git a/django/core/files/images.py b/django/core/files/images.py
index cdb89de2cc..579c32e11c 100644
--- a/django/core/files/images.py
+++ b/django/core/files/images.py
@@ -69,6 +69,10 @@ def get_image_dimensions(file_or_path, close=False):
# less bytes than expected. Skip and feed more data to the
# parser (ticket #24544).
pass
+ except RuntimeError:
+ # e.g. "RuntimeError: could not create decoder object" for
+ # WebP files. A different chunk_size may work.
+ pass
if p.image:
return p.image.size
chunk_size *= 2
diff --git a/tests/files/test.webp b/tests/files/test.webp
new file mode 100644
index 0000000000..ae871d14f7
--- /dev/null
+++ b/tests/files/test.webp
Binary files differ
diff --git a/tests/files/tests.py b/tests/files/tests.py
index 663d2d976f..b50061649a 100644
--- a/tests/files/tests.py
+++ b/tests/files/tests.py
@@ -343,6 +343,12 @@ class GetImageDimensionsTests(unittest.TestCase):
size = images.get_image_dimensions(fh)
self.assertEqual(size, (None, None))
+ def test_webp(self):
+ img_path = os.path.join(os.path.dirname(__file__), 'test.webp')
+ with open(img_path, 'rb') as fh:
+ size = images.get_image_dimensions(fh)
+ self.assertEqual(size, (540, 405))
+
class FileMoveSafeTests(unittest.TestCase):
def test_file_move_overwrite(self):