From 23e9fec869261fce86d57b89ecdc253c19595f2f Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 26 Jul 2024 16:51:49 +0200 Subject: [PATCH] pcx: Fix crash in broken files --- src/imageformats/pcx.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/imageformats/pcx.cpp b/src/imageformats/pcx.cpp index 22bce91..be12c8f 100644 --- a/src/imageformats/pcx.cpp +++ b/src/imageformats/pcx.cpp @@ -464,6 +464,8 @@ static bool readImage24(QImage &img, QDataStream &s, const PCXHEADER &header) return false; } + const unsigned int bpl = std::min(header.BytesPerLine, static_cast(header.width())); + for (int y = 0; y < header.height(); ++y) { if (s.atEnd()) { return false; @@ -480,7 +482,8 @@ static bool readImage24(QImage &img, QDataStream &s, const PCXHEADER &header) } uint *p = (uint *)img.scanLine(y); - for (int x = 0; x < header.width(); ++x) { + + for (unsigned int x = 0; x < bpl; ++x) { p[x] = qRgb(r_buf[x], g_buf[x], b_buf[x]); } }