From af70b075a1241977f7e13add4c79cb8200ca62ab Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 17 Aug 2026 13:40:42 +1000 Subject: [PATCH] Add decompression bomb check when loading at a different DPI --- Tests/test_file_wmf.py | 8 ++++++-- src/PIL/WmfImagePlugin.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_wmf.py b/Tests/test_file_wmf.py index c837583f15a..45aa80f56af 100644 --- a/Tests/test_file_wmf.py +++ b/Tests/test_file_wmf.py @@ -118,9 +118,13 @@ def test_load_set_dpi() -> None: with Image.open("Tests/images/drawing.emf") as im: assert im.size == (1625, 1625) + assert isinstance(im, WmfImagePlugin.WmfStubImageFile) + with pytest.raises(Image.DecompressionBombError): + im.load(20000) - if not hasattr(Image.core, "drawwmf"): - return + if not hasattr(Image.core, "drawwmf"): + return + with Image.open("Tests/images/drawing.emf") as im: assert isinstance(im, WmfImagePlugin.WmfStubImageFile) im.load(im.info["dpi"]) assert im.size == (1625, 1625) diff --git a/src/PIL/WmfImagePlugin.py b/src/PIL/WmfImagePlugin.py index 1815933b4c0..15dccae93fa 100644 --- a/src/PIL/WmfImagePlugin.py +++ b/src/PIL/WmfImagePlugin.py @@ -128,6 +128,7 @@ def load( int((x1 - x0) * dpi[0] / self._inch[0]), int((y1 - y0) * dpi[1] / self._inch[1]), ) + Image._decompression_bomb_check(self.size) return super().load()