From 71334c324e702c434d446e5fc329294c97b8516d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 4 Aug 2021 10:53:02 +0200 Subject: QXpmHandler: actually limit characters-per-pixel to four MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following code assumed, and all comments indicated, that the cpp variable was limited to a max of 4. Yet, as coded, cpp could be five, in which case the XPM would be corrupt, as the header suggested five characters-per-pixel while the data was formatted in only four. Add a warning and error out when we encounter this situation. [ChangeLog][QtGui][QImage] Instead of writing a corrupt file, rejects to write XPM files with more than 64^4 colors (more than four characters per pixel) now. Pick-to: 6.2 6.1 5.15 5.12 Change-Id: I458873cf7d179ab2e2dacd4c17dc837d640591a9 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Qt CI Bot Reviewed-by: Thiago Macieira --- src/gui/image/qxpmhandler.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/gui/image') diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp index 501f3067fc..22bfab684c 100644 --- a/src/gui/image/qxpmhandler.cpp +++ b/src/gui/image/qxpmhandler.cpp @@ -1145,8 +1145,11 @@ static bool write_xpm_image(const QImage &sourceImage, QIODevice *device, const ++cpp; // limit to 4 characters per pixel // 64^4 colors is enough for a 4096x4096 image - if (cpp > 4) - break; + if (cpp > 4) { + qCWarning(lcImageIo, "Qt does not support writing XPM images with more than " + "64^4 colors (requested: %d colors).", ncolors); + return false; + } } // write header -- cgit v1.2.3