diff --git a/Tests/images/ultrahdr.jpg b/Tests/images/ultrahdr.jpg new file mode 100644 index 00000000000..34f615b61aa Binary files /dev/null and b/Tests/images/ultrahdr.jpg differ diff --git a/Tests/test_file_mpo.py b/Tests/test_file_mpo.py index a5018870058..39b9c60b756 100644 --- a/Tests/test_file_mpo.py +++ b/Tests/test_file_mpo.py @@ -226,6 +226,11 @@ def test_eoferror() -> None: im.seek(n_frames - 1) +def test_ultra_hdr() -> None: + with Image.open("Tests/images/ultrahdr.jpg") as im: + assert im.format == "JPEG" + + @pytest.mark.parametrize("test_file", test_files) def test_image_grab(test_file: str) -> None: with Image.open(test_file) as im: diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index 9d6811cb759..b7d0d24f242 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -831,6 +831,10 @@ def jpeg_factory(fp=None, filename=None): try: mpheader = im._getmp() if mpheader[45057] > 1: + for segment, content in im.applist: + if segment == "APP1" and b' hdrgm:Version="' in content: + # Ultra HDR images are not yet supported + return im # It's actually an MPO from .MpoImagePlugin import MpoImageFile