mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Merge pull request #4102 from radarhere/decompression
Added decompression bomb checks
This commit is contained in:
		
						commit
						f228d0ccbf
					
				
							
								
								
									
										
											BIN
										
									
								
								Tests/images/decompression_bomb.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/decompression_bomb.gif
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 44 B  | 
							
								
								
									
										
											BIN
										
									
								
								Tests/images/decompression_bomb.ico
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/decompression_bomb.ico
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 58 B  | 
| 
						 | 
				
			
			@ -14,6 +14,7 @@ class TestDecompressionBomb(PillowTestCase):
 | 
			
		|||
    def test_no_warning_small_file(self):
 | 
			
		||||
        # Implicit assert: no warning.
 | 
			
		||||
        # A warning would cause a failure.
 | 
			
		||||
        Image.MAX_IMAGE_PIXELS = ORIGINAL_LIMIT
 | 
			
		||||
        Image.open(TEST_FILE)
 | 
			
		||||
 | 
			
		||||
    def test_no_warning_no_limit(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -41,6 +42,14 @@ class TestDecompressionBomb(PillowTestCase):
 | 
			
		|||
 | 
			
		||||
        self.assertRaises(Image.DecompressionBombError, lambda: Image.open(TEST_FILE))
 | 
			
		||||
 | 
			
		||||
    def test_exception_ico(self):
 | 
			
		||||
        with self.assertRaises(Image.DecompressionBombError):
 | 
			
		||||
            Image.open("Tests/images/decompression_bomb.ico")
 | 
			
		||||
 | 
			
		||||
    def test_exception_gif(self):
 | 
			
		||||
        with self.assertRaises(Image.DecompressionBombError):
 | 
			
		||||
            Image.open("Tests/images/decompression_bomb.gif")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestDecompressionCrop(PillowTestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -265,6 +265,7 @@ class GifImageFile(ImageFile.ImageFile):
 | 
			
		|||
                self.dispose = None
 | 
			
		||||
            elif self.disposal_method == 2:
 | 
			
		||||
                # replace with background colour
 | 
			
		||||
                Image._decompression_bomb_check(self.size)
 | 
			
		||||
                self.dispose = Image.core.fill("P", self.size, self.info["background"])
 | 
			
		||||
            else:
 | 
			
		||||
                # replace with previous contents
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -180,6 +180,7 @@ class IcoFile(object):
 | 
			
		|||
        else:
 | 
			
		||||
            # XOR + AND mask bmp frame
 | 
			
		||||
            im = BmpImagePlugin.DibImageFile(self.buf)
 | 
			
		||||
            Image._decompression_bomb_check(im.size)
 | 
			
		||||
 | 
			
		||||
            # change tile dimension to only encompass XOR image
 | 
			
		||||
            im._size = (im.size[0], int(im.size[1] / 2))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user