Fixed #29705 -- Fixed ImageField RuntimeError crash for WebP files.
This commit is contained in:
parent
586a9dc429
commit
c69d40f943
|
@ -69,6 +69,10 @@ def get_image_dimensions(file_or_path, close=False):
|
||||||
# less bytes than expected. Skip and feed more data to the
|
# less bytes than expected. Skip and feed more data to the
|
||||||
# parser (ticket #24544).
|
# parser (ticket #24544).
|
||||||
pass
|
pass
|
||||||
|
except RuntimeError:
|
||||||
|
# e.g. "RuntimeError: could not create decoder object" for
|
||||||
|
# WebP files. A different chunk_size may work.
|
||||||
|
pass
|
||||||
if p.image:
|
if p.image:
|
||||||
return p.image.size
|
return p.image.size
|
||||||
chunk_size *= 2
|
chunk_size *= 2
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
|
@ -343,6 +343,12 @@ class GetImageDimensionsTests(unittest.TestCase):
|
||||||
size = images.get_image_dimensions(fh)
|
size = images.get_image_dimensions(fh)
|
||||||
self.assertEqual(size, (None, None))
|
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):
|
class FileMoveSafeTests(unittest.TestCase):
|
||||||
def test_file_move_overwrite(self):
|
def test_file_move_overwrite(self):
|
||||||
|
|
Loading…
Reference in New Issue