Python PIL.Image.DecompressionBombWarning() Examples

The following are 4 code examples of PIL.Image.DecompressionBombWarning(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PIL.Image , or try the search function .
Example #1
Source File: test_decompression_bomb.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_crop_decompression_checks(self):

        im = Image.new("RGB", (100, 100))

        good_values = ((-9999, -9999, -9990, -9990),
                       (-999, -999, -990, -990))

        warning_values = ((-160, -160, 99, 99),
                          (160, 160, -99, -99))

        error_values = ((-99909, -99990, 99999, 99999),
                        (99909, 99990, -99999, -99999))

        for value in good_values:
            self.assertEqual(im.crop(value).size, (9, 9))

        for value in warning_values:
            self.assert_warning(Image.DecompressionBombWarning, im.crop, value)

        for value in error_values:
            with self.assertRaises(Image.DecompressionBombError):
                im.crop(value) 
Example #2
Source File: test_decompression_bomb.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_warning(self):
        # Set limit to trigger warning on the test file
        Image.MAX_IMAGE_PIXELS = 128 * 128 - 1
        self.assertEqual(Image.MAX_IMAGE_PIXELS, 128 * 128 - 1)

        self.assert_warning(Image.DecompressionBombWarning,
                            Image.open, TEST_FILE) 
Example #3
Source File: test_decompression_bomb.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testEnlargeCrop(self):
        # Crops can extend the extents, therefore we should have the
        # same decompression bomb warnings on them.
        box = (0, 0, self.src.width * 2, self.src.height * 2)
        self.assert_warning(Image.DecompressionBombWarning,
                            self.src.crop, box) 
Example #4
Source File: __init__.py    From omfvista with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def ignore_warnings():
    """Sets a warning filter for pillow's annoying ``DecompressionBombWarning``
    """
    import warnings
    from PIL import Image
    warnings.simplefilter(action='ignore', category=Image.DecompressionBombWarning)