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
8 changes: 8 additions & 0 deletions Tests/test_file_pcx.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ def test_1px_width(tmp_path: Path) -> None:
_roundtrip(tmp_path, im)


def test_rgb_odd_width(tmp_path: Path) -> None:
# An RGB (multi-plane) width whose even-padded stride differs from the
# width must still separate the colour planes correctly. Distinct channel
# values expose a misaligned split.
im = Image.new("RGB", (3, 3), (0x11, 0x22, 0x33))
_roundtrip(tmp_path, im)


def test_large_count(tmp_path: Path) -> None:
im = Image.new("L", (256, 1))
px = im.load()
Expand Down
10 changes: 6 additions & 4 deletions src/libImaging/PcxDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
stride = state->bytes / state->bits;
} else {
xsize = state->xsize;
bands = state->bytes / state->xsize;
if (bands != 0) {
stride = state->bytes / bands;
}
// state->bytes is planes * stride; derive the stride from the
// known band count rather than guessing it from state->xsize,
// which picks the wrong split when xsize != stride (e.g. an
// odd-width RGB line padded to an even stride).
bands = im->bands;
stride = state->bytes / bands;
}
if (stride > xsize) {
int i;
Expand Down
Loading