mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Fix crash on save when icc_profile is None
This commit is contained in:
		
							parent
							
								
									bb449f30ec
								
							
						
					
					
						commit
						0348fcac51
					
				| 
						 | 
					@ -618,7 +618,7 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
 | 
				
			||||||
            name = p.tags.desc.get("ASCII", p.tags.desc.get("Unicode", p.tags.desc.get("Macintosh", p.tags.desc.get("en", {}).get("US", "ICC Profile")))).encode("latin1", "replace")[:79]
 | 
					            name = p.tags.desc.get("ASCII", p.tags.desc.get("Unicode", p.tags.desc.get("Macintosh", p.tags.desc.get("en", {}).get("US", "ICC Profile")))).encode("latin1", "replace")[:79]
 | 
				
			||||||
        except ImportError:
 | 
					        except ImportError:
 | 
				
			||||||
            name = b"ICC Profile"
 | 
					            name = b"ICC Profile"
 | 
				
			||||||
        data = name + b"\0\0" + zlib.compress(im.info["icc_profile"])
 | 
					        data = name or b'ICC Profile' + b"\0\0" + zlib.compress(im.info["icc_profile"])
 | 
				
			||||||
        chunk(fp, b"iCCP", data)
 | 
					        chunk(fp, b"iCCP", data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ImageFile._save(im, _idat(fp, chunk), [("zip", (0,0)+im.size, 0, rawmode)])
 | 
					    ImageFile._save(im, _idat(fp, chunk), [("zip", (0,0)+im.size, 0, rawmode)])
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								Tests/images/icc_profile_none.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/icc_profile_none.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 4.0 KiB  | 
| 
						 | 
					@ -250,3 +250,10 @@ def test_trns_rgb():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    im = roundtrip(im, transparency=(0, 1, 2))
 | 
					    im = roundtrip(im, transparency=(0, 1, 2))
 | 
				
			||||||
    assert_equal(im.info["transparency"], (0, 1, 2))
 | 
					    assert_equal(im.info["transparency"], (0, 1, 2))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_save_icc_profile_none():
 | 
				
			||||||
 | 
					    in_file = "Tests/images/icc_profile_none.png"
 | 
				
			||||||
 | 
					    im = Image.open(in_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    file = tempfile("temp.png")
 | 
				
			||||||
 | 
					    assert_no_exception(lambda: im.save(file))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user