mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 18:07:51 +03:00 
			
		
		
		
	Raise an error when EXIF data is too long
This commit is contained in:
		
							parent
							
								
									4ab4bfe89b
								
							
						
					
					
						commit
						bb524018d3
					
				| 
						 | 
				
			
			@ -270,7 +270,10 @@ class TestFileJpeg:
 | 
			
		|||
        # https://github.com/python-pillow/Pillow/issues/148
 | 
			
		||||
        f = str(tmp_path / "temp.jpg")
 | 
			
		||||
        im = hopper()
 | 
			
		||||
        im.save(f, "JPEG", quality=90, exif=b"1" * 65532)
 | 
			
		||||
        im.save(f, "JPEG", quality=90, exif=b"1" * 65533)
 | 
			
		||||
 | 
			
		||||
        with pytest.raises(ValueError):
 | 
			
		||||
            im.save(f, "JPEG", quality=90, exif=b"1" * 65534)
 | 
			
		||||
 | 
			
		||||
    def test_exif_typeerror(self):
 | 
			
		||||
        with Image.open("Tests/images/exif_typeerror.jpg") as im:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -730,10 +730,10 @@ def _save(im, fp, filename):
 | 
			
		|||
 | 
			
		||||
    extra = info.get("extra", b"")
 | 
			
		||||
 | 
			
		||||
    MAX_BYTES_IN_MARKER = 65533
 | 
			
		||||
    icc_profile = info.get("icc_profile")
 | 
			
		||||
    if icc_profile:
 | 
			
		||||
        ICC_OVERHEAD_LEN = 14
 | 
			
		||||
        MAX_BYTES_IN_MARKER = 65533
 | 
			
		||||
        MAX_DATA_BYTES_IN_MARKER = MAX_BYTES_IN_MARKER - ICC_OVERHEAD_LEN
 | 
			
		||||
        markers = []
 | 
			
		||||
        while icc_profile:
 | 
			
		||||
| 
						 | 
				
			
			@ -764,6 +764,9 @@ def _save(im, fp, filename):
 | 
			
		|||
    exif = info.get("exif", b"")
 | 
			
		||||
    if isinstance(exif, Image.Exif):
 | 
			
		||||
        exif = exif.tobytes()
 | 
			
		||||
    if len(exif) > MAX_BYTES_IN_MARKER:
 | 
			
		||||
        msg = "EXIF data is too long"
 | 
			
		||||
        raise ValueError(msg)
 | 
			
		||||
 | 
			
		||||
    # get keyword arguments
 | 
			
		||||
    im.encoderconfig = (
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user