Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Tests/test_file_pcx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions src/libImaging/PcxDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading