From 46abe78b775e445974cfb9603640581b9fd9852c Mon Sep 17 00:00:00 2001 From: hugovk Date: Mon, 23 Jun 2014 10:53:08 +0300 Subject: [PATCH] Use a custom subclass of RuntimeWarning for DecompressionBombWarning --- PIL/Image.py | 5 ++++- Tests/test_decompression_bomb.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index ce78bfa1b..b0b90a20b 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -31,6 +31,9 @@ from PIL import VERSION, PILLOW_VERSION, _plugins import warnings +class DecompressionBombWarning(RuntimeWarning): + pass + class _imaging_not_installed: # module placeholder def __getattr__(self, id): @@ -2187,7 +2190,7 @@ def _decompression_bomb_check(size): "Image size (%d pixels) exceeds limit of %d pixels, " "could be decompression bomb DOS attack." % (pixels, MAX_IMAGE_PIXELS), - RuntimeWarning) + DecompressionBombWarning) def open(fp, mode="r"): diff --git a/Tests/test_decompression_bomb.py b/Tests/test_decompression_bomb.py index 1b3873c1b..53c8bb5e6 100644 --- a/Tests/test_decompression_bomb.py +++ b/Tests/test_decompression_bomb.py @@ -31,7 +31,7 @@ def test_warning(): # Act / Assert assert_warning( - RuntimeWarning, + DecompressionBombWarning, lambda: Image.open(test_file)) # End of file