mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
Merge pull request #3313 from dinkolubina/fix-img-crop
Fix _crop and tests
This commit is contained in:
commit
a3f7ce5b73
|
@ -61,6 +61,29 @@ class TestDecompressionCrop(PillowTestCase):
|
|||
self.assert_warning(Image.DecompressionBombWarning,
|
||||
self.src.crop, box)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -1117,12 +1117,9 @@ class Image(object):
|
|||
|
||||
x0, y0, x1, y1 = map(int, map(round, box))
|
||||
|
||||
if x1 < x0:
|
||||
x1 = x0
|
||||
if y1 < y0:
|
||||
y1 = y0
|
||||
absolute_values = (abs(x1 - x0), abs(y1 - y0))
|
||||
|
||||
_decompression_bomb_check((x1, y1))
|
||||
_decompression_bomb_check(absolute_values)
|
||||
|
||||
return im.crop((x0, y0, x1, y1))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user