Avoid reading invalid images in doc::read_image()

This commit is contained in:
David Capello 2015-04-10 11:26:36 -03:00
parent 8353e45ae8
commit 045ece4114

View File

@ -99,6 +99,14 @@ Image* read_image(std::istream& is, bool setId)
int height = read16(is); // Height
uint32_t maskColor = read32(is); // Mask color
if ((pixelFormat != IMAGE_RGB &&
pixelFormat != IMAGE_GRAYSCALE &&
pixelFormat != IMAGE_INDEXED &&
pixelFormat != IMAGE_BITMAP) ||
(width < 1 || height < 1) ||
(width > 0xfffff || height > 0xfffff))
return nullptr;
base::UniquePtr<Image> image(Image::create(static_cast<PixelFormat>(pixelFormat), width, height));
int rowSize = image->getRowStrideSize();