Index: Source/platform/image-decoders/ico/ICOImageDecoder.cpp |
diff --git a/Source/platform/image-decoders/ico/ICOImageDecoder.cpp b/Source/platform/image-decoders/ico/ICOImageDecoder.cpp |
index 06dce8e51035e6f192292e52224884faebbab5c7..14bf784db393d90e9bc9228cdbf2883fccf4161c 100644 |
--- a/Source/platform/image-decoders/ico/ICOImageDecoder.cpp |
+++ b/Source/platform/image-decoders/ico/ICOImageDecoder.cpp |
@@ -216,8 +216,11 @@ bool ICOImageDecoder::decodeAtIndex(size_t index) |
// We need to have already sized m_frameBufferCache before this, and |
// we must not resize it again later (see caution in frameCount()). |
ASSERT(m_frameBufferCache.size() == m_dirEntries.size()); |
- m_bmpReaders[index] = adoptPtr(new BMPImageReader(this, dirEntry.m_imageOffset, 0, true)); |
- m_bmpReaders[index]->setData(m_data.get()); |
+ // Make sure the image data doesn't go beyond the end of the file. |
+ uint32_t imageSize = std::min(dirEntry.m_imageSize, m_data->size() - dirEntry.m_imageOffset); |
+ RefPtr<SharedBuffer> bmpData(SharedBuffer::create(&m_data->data()[dirEntry.m_imageOffset], imageSize)); |
+ m_bmpReaders[index] = adoptPtr(new BMPImageReader(this, 0, 0, true)); |
+ m_bmpReaders[index]->setData(bmpData.get()); |
Peter Kasting
2014/11/18 20:59:05
I have three concerns with this code, in decreasin
|
m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]); |
} |
m_frameSize = dirEntry.m_size; |
@@ -314,6 +317,7 @@ ICOImageDecoder::IconDirectoryEntry ICOImageDecoder::readDirectoryEntry() |
entry.m_bitCount = readUint16(6); |
entry.m_hotSpot = IntPoint(); |
} |
+ entry.m_imageSize = readUint32(8); |
entry.m_imageOffset = readUint32(12); |
// Some icons don't have a bit depth, only a color count. Convert the |