mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 07:57:27 +03:00 
			
		
		
		
	Merge pull request #2596 from Darou/master
Adjust buffer size when icc_profile > MAXBLOCK (issue #148)
This commit is contained in:
		
						commit
						9bc50d8f5c
					
				|  | @ -732,8 +732,9 @@ def _save(im, fp, filename): | |||
|             bufsize = im.size[0] * im.size[1] | ||||
| 
 | ||||
|     # The exif info needs to be written as one block, + APP1, + one spare byte. | ||||
|     # Ensure that our buffer is big enough | ||||
|     bufsize = max(ImageFile.MAXBLOCK, bufsize, len(info.get("exif", b"")) + 5) | ||||
|     # Ensure that our buffer is big enough. Same with the icc_profile block. | ||||
|     bufsize = max(ImageFile.MAXBLOCK, bufsize, len(info.get("exif", b"")) + 5, | ||||
|                   len(extra) + 1) | ||||
| 
 | ||||
|     ImageFile._save(im, fp, [("jpeg", (0, 0)+im.size, 0, rawmode)], bufsize) | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										
											BIN
										
									
								
								Tests/images/icc_profile_big.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/icc_profile_big.jpg
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 500 KiB | 
|  | @ -133,6 +133,19 @@ class TestFileJpeg(PillowTestCase): | |||
|         test(ImageFile.MAXBLOCK+1)  # full buffer block plus one byte | ||||
|         test(ImageFile.MAXBLOCK*4+3)  # large block | ||||
| 
 | ||||
|     def test_large_icc_meta(self): | ||||
|         # https://github.com/python-pillow/Pillow/issues/148 | ||||
|         # Sometimes the meta data on the icc_profile block is bigger than | ||||
|         # Image.MAXBLOCK or the image size. | ||||
|         im = Image.open('Tests/images/icc_profile_big.jpg') | ||||
|         f = self.tempfile("temp.jpg") | ||||
|         icc_profile = im.info["icc_profile"] | ||||
|         try: | ||||
|             im.save(f, format='JPEG', progressive=True,quality=95, | ||||
|                     icc_profile=icc_profile, optimize=True) | ||||
|         except IOError: | ||||
|             self.fail("Failed saving image with icc larger than image size") | ||||
| 
 | ||||
|     def test_optimize(self): | ||||
|         im1 = self.roundtrip(hopper()) | ||||
|         im2 = self.roundtrip(hopper(), optimize=0) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user