mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Treat MPO with unknown header as base JPEG file
This commit is contained in:
parent
df02be0c70
commit
2a3a34d2ff
|
@ -37,6 +37,7 @@ __version__ = "0.6"
|
|||
import array
|
||||
import struct
|
||||
import io
|
||||
import warnings
|
||||
from struct import unpack
|
||||
from PIL import Image, ImageFile, TiffImagePlugin, _binary
|
||||
from PIL.JpegPresets import presets
|
||||
|
@ -713,8 +714,8 @@ def _save_cjpeg(im, fp, filename):
|
|||
# Factory for making JPEG and MPO instances
|
||||
def jpeg_factory(fp=None, filename=None):
|
||||
im = JpegImageFile(fp, filename)
|
||||
mpheader = im._getmp()
|
||||
try:
|
||||
mpheader = im._getmp()
|
||||
if mpheader[45057] > 1:
|
||||
# It's actually an MPO
|
||||
from .MpoImagePlugin import MpoImageFile
|
||||
|
@ -722,6 +723,10 @@ def jpeg_factory(fp=None, filename=None):
|
|||
except (TypeError, IndexError):
|
||||
# It is really a JPEG
|
||||
pass
|
||||
except SyntaxError:
|
||||
warnings.warn("Image appears to be a malformed MPO file, it will be "
|
||||
"interpreted as a base JPEG file")
|
||||
pass
|
||||
return im
|
||||
|
||||
|
||||
|
|
BIN
Tests/images/sugarshack_bad_mpo_header.jpg
Normal file
BIN
Tests/images/sugarshack_bad_mpo_header.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 117 KiB |
|
@ -353,6 +353,17 @@ class TestFileJpeg(PillowTestCase):
|
|||
reloaded.save(f, quality='keep', progressive=True)
|
||||
reloaded.save(f, quality='keep', optimize=True)
|
||||
|
||||
def test_bad_mpo_header(self):
|
||||
""" Treat unknown MPO as JPEG """
|
||||
# Arrange
|
||||
|
||||
# Act
|
||||
# Shouldn't raise error
|
||||
im = Image.open("Tests/images/sugarshack_bad_mpo_header.jpg")
|
||||
|
||||
# Assert
|
||||
self.assertEqual(im.format, "JPEG")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue
Block a user