From 4478bc8d2bc63c98fa87b26e19b3b4a42fcffa8f Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Wed, 24 Jul 2024 23:38:51 +0200 Subject: [PATCH] xcf: Fix crash on broken files --- src/imageformats/xcf.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/imageformats/xcf.cpp b/src/imageformats/xcf.cpp index b2fb773..6611d9a 100644 --- a/src/imageformats/xcf.cpp +++ b/src/imageformats/xcf.cpp @@ -1672,8 +1672,12 @@ bool XCFImageFormat::assignImageBytes(Layer &layer, uint i, uint j, const GimpPr for (int y = 0; y < height; y++) { uchar *dataPtr = bits + y * bytesPerLine; uchar *alphaPtr = nullptr; - if (!layer.alpha_tiles.isEmpty()) - alphaPtr = layer.alpha_tiles[j][i].scanLine(y); + if (!layer.alpha_tiles.isEmpty()) { + QImage &alphaTile = layer.alpha_tiles[j][i]; + if (alphaTile.width() >= width && alphaTile.height() > y) { + alphaPtr = alphaTile.scanLine(y); + } + } if (bpc == 4) { #ifdef USE_FLOAT_IMAGES if (precision < GimpPrecision::GIMP_PRECISION_HALF_LINEAR) {