Add some sanity and bounds checking

Since QImage does sanity checking for overflows and stuff wrt.
dimensions and depth, check for QImage::isNull() as early as possible to
see if there's some funky business going on.

Also tried to add some checks wherever we wrote to "raw" memory.

Unit tests pass, and tested converting some files from
https://samples.ffmpeg.org/image-samples/ to pngs, and that seemed to
work.

Reviewed By: aacid

Differential Revision: https://phabricator.kde.org/D24367
This commit is contained in:
Martin T. H. Sandsmark
2019-10-02 17:39:59 +02:00
parent f5b26cc9f9
commit 8562ce18f1
6 changed files with 106 additions and 12 deletions

View File

@ -253,6 +253,11 @@ bool SoftimagePICHandler::read(QImage *image)
}
QImage img(m_header.width, m_header.height, fmt);
if (img.isNull()) {
qDebug() << "Failed to allocate image, invalid dimensions?" << QSize(m_header.width, m_header.height) << fmt;
return false;
}
img.fill(qRgb(0,0,0));
for (int y = 0; y < m_header.height; y++) {
@ -362,6 +367,7 @@ bool SoftimagePICHandler::readHeader()
m_state = ReadHeader;
}
}
return m_state != Error;
}