From 2b80a0a55a3d01e79fb5ee10783af5f05d688684 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Tue, 14 Oct 2025 23:55:59 +0200 Subject: [PATCH] Fix assert on broken data The nan eventually ends up in qRound inside Qt code. That asserts because it doesn't know what to do with a nan --- src/imageformats/xcf.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/imageformats/xcf.cpp b/src/imageformats/xcf.cpp index 562388a..329e4aa 100644 --- a/src/imageformats/xcf.cpp +++ b/src/imageformats/xcf.cpp @@ -1808,7 +1808,18 @@ bool XCFImageFormat::assignImageBytes(Layer &layer, uint i, uint j, const GimpPr } break; case QImage::Format_RGBA16FPx4: - static_assert(sizeof(QRgbaFloat16) == sizeof(QRgba64), "Different sizes for float and int 16 bit pixels"); + for (int y = 0; y < height; y++) { + const size_t bpl = width * sizeof(QRgbaFloat16); + qFromBigEndian(tile + y * bpl, width * 4, image.scanLine(y)); + + const qfloat16 *dataPtr = reinterpret_cast(image.scanLine(y)); + for (int x = 0; x < width * 4; ++x) { + if (dataPtr[x].isNaN()) { + return false; + } + } + } + break; #endif case QImage::Format_RGBA64: for (int y = 0; y < height; y++) { @@ -1821,6 +1832,13 @@ bool XCFImageFormat::assignImageBytes(Layer &layer, uint i, uint j, const GimpPr for (int y = 0; y < height; y++) { const size_t bpl = width * sizeof(QRgbaFloat32); qFromBigEndian(tile + y * bpl, width * 4, image.scanLine(y)); + + const float *dataPtr = reinterpret_cast(image.scanLine(y)); + for (int x = 0; x < width * 4; ++x) { + if (std::isnan(dataPtr[x])) { + return false; + } + } } break; case QImage::Format_RGBX32FPx4: