tga: fail gracefully if readRawData errors

oss-fuzz/12818
This commit is contained in:
Albert Astals Cid 2019-02-03 13:47:20 +01:00
parent 1a31500e55
commit a51cbd865f

View File

@ -206,6 +206,9 @@ static bool LoadTGA(QDataStream &s, const TgaHeader &tga, QImage &img)
// @todo Support palettes in other formats!
const int size = 3 * tga.colormap_length;
const int dataRead = s.readRawData(palette, size);
if (dataRead < 0) {
return false;
}
if (dataRead < size) {
memset(&palette[dataRead], 0, size - dataRead);
}
@ -260,6 +263,10 @@ static bool LoadTGA(QDataStream &s, const TgaHeader &tga, QImage &img)
} else {
// Read raw image.
const int dataRead = s.readRawData((char *)image, size);
if (dataRead < 0) {
free(image);
return false;
}
if (dataRead < size) {
memset(&image[dataRead], 0, size - dataRead);
}