mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Test not enough image data
This commit is contained in:
		
							parent
							
								
									395bd6bd12
								
							
						
					
					
						commit
						6512a8e371
					
				| 
						 | 
				
			
			@ -1,5 +1,7 @@
 | 
			
		|||
from __future__ import annotations
 | 
			
		||||
 | 
			
		||||
from io import BytesIO
 | 
			
		||||
 | 
			
		||||
import pytest
 | 
			
		||||
 | 
			
		||||
from PIL import Image, XpmImagePlugin
 | 
			
		||||
| 
						 | 
				
			
			@ -31,6 +33,14 @@ def test_rgb() -> None:
 | 
			
		|||
        assert_image_similar(im, hopper(), 16)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_not_enough_image_data() -> None:
 | 
			
		||||
    with open(TEST_FILE, "rb") as fp:
 | 
			
		||||
        data = fp.read().split(b"/* pixels */")[0]
 | 
			
		||||
        with Image.open(BytesIO(data)) as im:
 | 
			
		||||
            with pytest.raises(ValueError, match="not enough image data"):
 | 
			
		||||
                im.load()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_invalid_file() -> None:
 | 
			
		||||
    invalid_file = "Tests/images/flower.jpg"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -125,11 +125,11 @@ class XpmDecoder(ImageFile.PyDecoder):
 | 
			
		|||
        pixel_header = False
 | 
			
		||||
        while len(data) < dest_length:
 | 
			
		||||
            s = self.fd.readline()
 | 
			
		||||
            if not s:
 | 
			
		||||
                break
 | 
			
		||||
            if s.rstrip() == b"/* pixels */" and not pixel_header:
 | 
			
		||||
                pixel_header = True
 | 
			
		||||
                continue
 | 
			
		||||
            if not s:
 | 
			
		||||
                break
 | 
			
		||||
            s = b'"'.join(s.split(b'"')[1:-1])
 | 
			
		||||
            for i in range(0, len(s), bpp):
 | 
			
		||||
                key = s[i : i + bpp]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user