tga: Fix Use-of-uninitialized-value on broken files

oss-fuzz/12776
This commit is contained in:
Albert Astals Cid 2019-01-31 01:35:39 +01:00
parent e7f3c0be44
commit 8b8330b0fe

View File

@ -204,7 +204,11 @@ static bool LoadTGA(QDataStream &s, const TgaHeader &tga, QImage &img)
char palette[768]; char palette[768];
if (info.pal) { if (info.pal) {
// @todo Support palettes in other formats! // @todo Support palettes in other formats!
s.readRawData(palette, 3 * tga.colormap_length); const int size = 3 * tga.colormap_length;
const int dataRead = s.readRawData(palette, size);
if (dataRead < size) {
memset(&palette[dataRead], 0, size - dataRead);
}
} }
// Allocate image. // Allocate image.
@ -255,7 +259,10 @@ static bool LoadTGA(QDataStream &s, const TgaHeader &tga, QImage &img)
} }
} else { } else {
// Read raw image. // Read raw image.
s.readRawData((char *)image, size); const int dataRead = s.readRawData((char *)image, size);
if (dataRead < size) {
memset(&image[dataRead], 0, size - dataRead);
}
} }
if (!valid) { if (!valid) {