mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 01:04:29 +03:00
Don't use gigs of memory with invalid palette sizes
This commit is contained in:
parent
7d76ae2d91
commit
046a226f34
|
@ -129,6 +129,8 @@ class BmpImageFile(ImageFile.ImageFile):
|
||||||
greyscale = 1
|
greyscale = 1
|
||||||
if colors == 2:
|
if colors == 2:
|
||||||
indices = (0, 255)
|
indices = (0, 255)
|
||||||
|
elif colors > 2**16 or colors <=0: #We're reading a i32.
|
||||||
|
raise IOError("Unsupported BMP Palette size (%d)" % colors)
|
||||||
else:
|
else:
|
||||||
indices = list(range(colors))
|
indices = list(range(colors))
|
||||||
for i in indices:
|
for i in indices:
|
||||||
|
|
25
Tests/bmpsuite.py
Normal file
25
Tests/bmpsuite.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
from tester import *
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
import os
|
||||||
|
|
||||||
|
base = 'Tests/images/bmp/'
|
||||||
|
|
||||||
|
|
||||||
|
def get_files(d, ext='.bmp'):
|
||||||
|
return [os.path.join(base,d,f) for f
|
||||||
|
in os.listdir(os.path.join(base, d)) if ext in f]
|
||||||
|
|
||||||
|
def test_bad():
|
||||||
|
""" These shouldn't crash, but they shouldn't return anything either """
|
||||||
|
for f in get_files('b'):
|
||||||
|
try:
|
||||||
|
print ("Trying %s"%f)
|
||||||
|
im = Image.open(f)
|
||||||
|
print ("%s, %s" %(im.size, im.mode))
|
||||||
|
im.load()
|
||||||
|
except Exception as msg:
|
||||||
|
print ("Bad Image %s: %s" %(f,msg))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user