diff --git a/Tests/test_file_pcx.py b/Tests/test_file_pcx.py index 76fd09dac9b..c3573bbfccc 100644 --- a/Tests/test_file_pcx.py +++ b/Tests/test_file_pcx.py @@ -80,13 +80,14 @@ def test_invalid_file() -> None: @pytest.mark.parametrize("mode", ("1", "L", "P", "RGB")) -def test_odd(tmp_path: Path, mode: str) -> None: +@pytest.mark.parametrize("size", (3, 511)) +def test_odd(tmp_path: Path, mode: str, size: int) -> None: # See issue #523, odd sized images should have a stride that's even. # Not that ImageMagick or GIMP write PCX that way. # We were not handling properly. # larger, odd sized images are better here to ensure that # we handle interrupted scan lines properly. - _roundtrip(tmp_path, hopper(mode).resize((511, 511))) + _roundtrip(tmp_path, hopper(mode).resize((size, size))) def test_odd_read() -> None: diff --git a/src/libImaging/PcxDecode.c b/src/libImaging/PcxDecode.c index a65952fb1da..d060be3e7bc 100644 --- a/src/libImaging/PcxDecode.c +++ b/src/libImaging/PcxDecode.c @@ -62,18 +62,14 @@ ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt if (state->x >= state->bytes) { int bands; int xsize = 0; - int stride = 0; if (state->bits == 2 || state->bits == 4) { xsize = (state->xsize + 7) / 8; bands = state->bits; - stride = state->bytes / state->bits; } else { xsize = state->xsize; - bands = state->bytes / state->xsize; - if (bands != 0) { - stride = state->bytes / bands; - } + bands = im->bands; } + int stride = state->bytes / bands; if (stride > xsize) { int i; for (i = 1; i < bands; i++) { // note -- skipping first band