From acd6b3970c96ed7f4e0ed6ab2f0abb63bef304a8 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Tue, 23 Jul 2024 00:22:08 +0200 Subject: [PATCH] pcx: fix crash on invalid files --- src/imageformats/pcx.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/imageformats/pcx.cpp b/src/imageformats/pcx.cpp index a5d283d..22bce91 100644 --- a/src/imageformats/pcx.cpp +++ b/src/imageformats/pcx.cpp @@ -375,7 +375,8 @@ static bool readImage4v2(QImage &img, QDataStream &s, const PCXHEADER &header) return false; } - for (unsigned int x = 0; x < header.BytesPerLine; ++x) { + const unsigned int bpl = std::min(header.BytesPerLine, static_cast(header.width() / 2)); + for (unsigned int x = 0; x < bpl; ++x) { p[x * 2] = (buf[x] & 240) >> 4; p[x * 2 + 1] = buf[x] & 15; }