mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Merge pull request #1350 from radarhere/1328_mpo_fix
Treat MPO with unknown header as base JPEG file
This commit is contained in:
commit
e1fb53f83f
|
@ -37,6 +37,7 @@ __version__ = "0.6"
|
||||||
import array
|
import array
|
||||||
import struct
|
import struct
|
||||||
import io
|
import io
|
||||||
|
import warnings
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
from PIL import Image, ImageFile, TiffImagePlugin, _binary
|
from PIL import Image, ImageFile, TiffImagePlugin, _binary
|
||||||
from PIL.JpegPresets import presets
|
from PIL.JpegPresets import presets
|
||||||
|
@ -713,8 +714,8 @@ def _save_cjpeg(im, fp, filename):
|
||||||
# Factory for making JPEG and MPO instances
|
# Factory for making JPEG and MPO instances
|
||||||
def jpeg_factory(fp=None, filename=None):
|
def jpeg_factory(fp=None, filename=None):
|
||||||
im = JpegImageFile(fp, filename)
|
im = JpegImageFile(fp, filename)
|
||||||
mpheader = im._getmp()
|
|
||||||
try:
|
try:
|
||||||
|
mpheader = im._getmp()
|
||||||
if mpheader[45057] > 1:
|
if mpheader[45057] > 1:
|
||||||
# It's actually an MPO
|
# It's actually an MPO
|
||||||
from .MpoImagePlugin import MpoImageFile
|
from .MpoImagePlugin import MpoImageFile
|
||||||
|
@ -722,6 +723,10 @@ def jpeg_factory(fp=None, filename=None):
|
||||||
except (TypeError, IndexError):
|
except (TypeError, IndexError):
|
||||||
# It is really a JPEG
|
# It is really a JPEG
|
||||||
pass
|
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
|
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', progressive=True)
|
||||||
reloaded.save(f, quality='keep', optimize=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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user