Test incoming formats more throuroughly
Just to protect against invalid data in d->format. Change-Id: I5e7cc04d5d8e42bdcb0edd2ab5fa34a08b96b6a8 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
parent
22c66e12e4
commit
35ef3fb009
@ -126,7 +126,7 @@ QImageData::QImageData()
|
|||||||
*/
|
*/
|
||||||
QImageData * QImageData::create(const QSize &size, QImage::Format format)
|
QImageData * QImageData::create(const QSize &size, QImage::Format format)
|
||||||
{
|
{
|
||||||
if (size.isEmpty() || format == QImage::Format_Invalid)
|
if (size.isEmpty() || format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
|
||||||
return nullptr; // invalid parameter(s)
|
return nullptr; // invalid parameter(s)
|
||||||
|
|
||||||
Q_TRACE_SCOPE(QImageData_create, size, format);
|
Q_TRACE_SCOPE(QImageData_create, size, format);
|
||||||
@ -791,7 +791,7 @@ QImage::QImage(const QSize &size, Format format)
|
|||||||
|
|
||||||
QImageData *QImageData::create(uchar *data, int width, int height, qsizetype bpl, QImage::Format format, bool readOnly, QImageCleanupFunction cleanupFunction, void *cleanupInfo)
|
QImageData *QImageData::create(uchar *data, int width, int height, qsizetype bpl, QImage::Format format, bool readOnly, QImageCleanupFunction cleanupFunction, void *cleanupInfo)
|
||||||
{
|
{
|
||||||
if (width <= 0 || height <= 0 || !data || format == QImage::Format_Invalid)
|
if (width <= 0 || height <= 0 || !data || format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
const int depth = qt_depthForFormat(format);
|
const int depth = qt_depthForFormat(format);
|
||||||
@ -2072,7 +2072,7 @@ QImage QImage::convertToFormat_helper(Format format, Qt::ImageConversionFlags fl
|
|||||||
if (!d || d->format == format)
|
if (!d || d->format == format)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
if (format == Format_Invalid || d->format == Format_Invalid)
|
if (d->format == Format_Invalid || format <= Format_Invalid || format >= NImageFormats)
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
||||||
const QPixelLayout *destLayout = &qPixelLayouts[format];
|
const QPixelLayout *destLayout = &qPixelLayouts[format];
|
||||||
@ -2202,7 +2202,7 @@ QImage QImage::convertToFormat(Format format, const QList<QRgb> &colorTable, Qt:
|
|||||||
if (!d || d->format == format)
|
if (!d || d->format == format)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
if (format == QImage::Format_Invalid)
|
if (format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
|
||||||
return QImage();
|
return QImage();
|
||||||
if (format <= QImage::Format_Indexed8)
|
if (format <= QImage::Format_Indexed8)
|
||||||
return convertWithPalette(convertToFormat(QImage::Format_ARGB32, flags), format, colorTable);
|
return convertWithPalette(convertToFormat(QImage::Format_ARGB32, flags), format, colorTable);
|
||||||
@ -2268,7 +2268,10 @@ bool QImage::reinterpretAsFormat(Format format)
|
|||||||
|
|
||||||
void QImage::convertTo(Format format, Qt::ImageConversionFlags flags)
|
void QImage::convertTo(Format format, Qt::ImageConversionFlags flags)
|
||||||
{
|
{
|
||||||
if (!d || format == QImage::Format_Invalid || d->format == format)
|
if (!d || format <= QImage::Format_Invalid || format >= QImage::NImageFormats)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (d->format == format)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
detach();
|
detach();
|
||||||
@ -5336,7 +5339,7 @@ QPixelFormat QImage::pixelFormat() const noexcept
|
|||||||
*/
|
*/
|
||||||
QPixelFormat QImage::toPixelFormat(QImage::Format format) noexcept
|
QPixelFormat QImage::toPixelFormat(QImage::Format format) noexcept
|
||||||
{
|
{
|
||||||
Q_ASSERT(static_cast<int>(format) < NImageFormats);
|
Q_ASSERT(static_cast<int>(format) < NImageFormats && static_cast<int>(format) >= 0);
|
||||||
return pixelformats[format];
|
return pixelformats[format];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user