Added dataBuf size check before calling PngChunk::decodeIHDRChunk

- cdataBuf must be at least 8 bytes long otherwise decodeIHDRChunk
  reads out of bounds
- pngImage::readMetadata now skips png chunks where the offset for
  IHDR chunks is invalid
- added assertion into PngChunk::decodeIHDRChunk() to ensure dataBuf
  size
This commit is contained in:
Dan Čermák 2018-02-14 23:09:18 +01:00
parent a1ab522eda
commit 751fba8b54
2 changed files with 5 additions and 1 deletions

View File

@ -64,6 +64,8 @@ namespace Exiv2 {
int* outWidth,
int* outHeight)
{
assert(data.size_ >= 8);
// Extract image width and height from IHDR chunk.
*outWidth = getLong((const byte*)data.pData_, bigEndian);

View File

@ -435,7 +435,9 @@ namespace Exiv2 {
#ifdef DEBUG
std::cout << "Exiv2::PngImage::readMetadata: Found IHDR chunk (length: " << dataOffset << ")\n";
#endif
PngChunk::decodeIHDRChunk(cdataBuf, &pixelWidth_, &pixelHeight_);
if (cdataBuf.size_ >= 8) {
PngChunk::decodeIHDRChunk(cdataBuf, &pixelWidth_, &pixelHeight_);
}
}
else if (!memcmp(cheaderBuf.pData_ + 4, "tEXt", 4))
{