Catch PCX P mode buffer overrun

This commit is contained in:
Andrew Murray 2019-12-21 18:38:22 +11:00
parent c40bc25847
commit 8f0c8f7311
3 changed files with 9 additions and 1 deletions

Binary file not shown.

View File

@ -590,7 +590,12 @@ class TestImage(PillowTestCase):
self.assertFalse(fp.closed)
def test_overrun(self):
for file in ["fli_overrun.bin", "sgi_overrun.bin", "pcx_overrun.bin"]:
for file in [
"fli_overrun.bin",
"sgi_overrun.bin",
"pcx_overrun.bin",
"pcx_overrun2.bin",
]:
with Image.open(os.path.join("Tests/images", file)) as im:
try:
im.load()

View File

@ -25,6 +25,9 @@ ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8* buf, Py_ssize_t byt
if (strcmp(im->mode, "1") == 0 && state->xsize > state->bytes * 8) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
} else if (strcmp(im->mode, "P") == 0 && state->xsize > state->bytes) {
state->errcode = IMAGING_CODEC_OVERRUN;
return -1;
}
ptr = buf;