QXpmHandler: actually limit characters-per-pixel to four

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.

Change-Id: I458873cf7d179ab2e2dacd4c17dc837d640591a9
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 71334c324e702c434d446e5fc329294c97b8516d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2021-08-04 10:53:02 +02:00 committed by Qt Cherry-pick Bot
parent 36760514a9
commit e0c6f50849

View File

@ -1137,8 +1137,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