Skip to content

Commit

Permalink
Fixed #29705 -- Fixed ImageField RuntimeError crash for WebP files.
Browse files Browse the repository at this point in the history
  • Loading branch information
winkidney authored and timgraham committed Aug 23, 2018
1 parent 586a9dc commit c69d40f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions django/core/files/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added tests/files/test.webp
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/files/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ def test_valid_image(self):
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):
Expand Down

0 comments on commit c69d40f

Please sign in to comment.