Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: Source/platform/image-decoders/ico/ICOImageDecoder.cpp

Issue 733063005: Don't decode AND mask for an icon that already has alpha information (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Clamp size later. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/image-decoders/ico/ICOImageDecoder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved. 2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 const IconDirectoryEntry& dirEntry = m_dirEntries[index]; 209 const IconDirectoryEntry& dirEntry = m_dirEntries[index];
210 const ImageType imageType = imageTypeAtIndex(index); 210 const ImageType imageType = imageTypeAtIndex(index);
211 if (imageType == Unknown) 211 if (imageType == Unknown)
212 return false; // Not enough data to determine image type yet. 212 return false; // Not enough data to determine image type yet.
213 213
214 if (imageType == BMP) { 214 if (imageType == BMP) {
215 if (!m_bmpReaders[index]) { 215 if (!m_bmpReaders[index]) {
216 // We need to have already sized m_frameBufferCache before this, and 216 // We need to have already sized m_frameBufferCache before this, and
217 // we must not resize it again later (see caution in frameCount()). 217 // we must not resize it again later (see caution in frameCount()).
218 ASSERT(m_frameBufferCache.size() == m_dirEntries.size()); 218 ASSERT(m_frameBufferCache.size() == m_dirEntries.size());
219 m_bmpReaders[index] = adoptPtr(new BMPImageReader(this, dirEntry.m_i mageOffset, 0, true)); 219 // Make sure the image data doesn't go beyond the end of the file.
220 m_bmpReaders[index]->setData(m_data.get()); 220 uint32_t imageSize = std::min(dirEntry.m_imageSize, m_data->size() - dirEntry.m_imageOffset);
221 RefPtr<SharedBuffer> bmpData(SharedBuffer::create(&m_data->data()[di rEntry.m_imageOffset], imageSize));
222 m_bmpReaders[index] = adoptPtr(new BMPImageReader(this, 0, 0, true)) ;
223 m_bmpReaders[index]->setData(bmpData.get());
Peter Kasting 2014/11/18 20:59:05 I have three concerns with this code, in decreasin
221 m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]); 224 m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]);
222 } 225 }
223 m_frameSize = dirEntry.m_size; 226 m_frameSize = dirEntry.m_size;
224 bool result = m_bmpReaders[index]->decodeBMP(false); 227 bool result = m_bmpReaders[index]->decodeBMP(false);
225 m_frameSize = IntSize(); 228 m_frameSize = IntSize();
226 return result; 229 return result;
227 } 230 }
228 231
229 if (!m_pngDecoders[index]) { 232 if (!m_pngDecoders[index]) {
230 m_pngDecoders[index] = adoptPtr( 233 m_pngDecoders[index] = adoptPtr(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 height = 256; 310 height = 256;
308 IconDirectoryEntry entry; 311 IconDirectoryEntry entry;
309 entry.m_size = IntSize(width, height); 312 entry.m_size = IntSize(width, height);
310 if (m_fileType == CURSOR) { 313 if (m_fileType == CURSOR) {
311 entry.m_bitCount = 0; 314 entry.m_bitCount = 0;
312 entry.m_hotSpot = IntPoint(readUint16(4), readUint16(6)); 315 entry.m_hotSpot = IntPoint(readUint16(4), readUint16(6));
313 } else { 316 } else {
314 entry.m_bitCount = readUint16(6); 317 entry.m_bitCount = readUint16(6);
315 entry.m_hotSpot = IntPoint(); 318 entry.m_hotSpot = IntPoint();
316 } 319 }
320 entry.m_imageSize = readUint32(8);
317 entry.m_imageOffset = readUint32(12); 321 entry.m_imageOffset = readUint32(12);
318 322
319 // Some icons don't have a bit depth, only a color count. Convert the 323 // Some icons don't have a bit depth, only a color count. Convert the
320 // color count to the minimum necessary bit depth. It doesn't matter if 324 // color count to the minimum necessary bit depth. It doesn't matter if
321 // this isn't quite what the bitmap info header says later, as we only use 325 // this isn't quite what the bitmap info header says later, as we only use
322 // this value to determine which icon entry is best. 326 // this value to determine which icon entry is best.
323 if (!entry.m_bitCount) { 327 if (!entry.m_bitCount) {
324 int colorCount = static_cast<uint8_t>(m_data->data()[m_decodedOffset + 2 ]); 328 int colorCount = static_cast<uint8_t>(m_data->data()[m_decodedOffset + 2 ]);
325 if (!colorCount) 329 if (!colorCount)
326 colorCount = 256; // Vague in the spec, needed by real-world icons. 330 colorCount = 256; // Vague in the spec, needed by real-world icons.
(...skipping 10 matching lines...) Expand all
337 // Check if this entry is a BMP or a PNG; we need 4 bytes to check the magic 341 // Check if this entry is a BMP or a PNG; we need 4 bytes to check the magic
338 // number. 342 // number.
339 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); 343 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size());
340 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; 344 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset;
341 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) 345 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4))
342 return Unknown; 346 return Unknown;
343 return strncmp(&m_data->data()[imageOffset], "\x89PNG", 4) ? BMP : PNG; 347 return strncmp(&m_data->data()[imageOffset], "\x89PNG", 4) ? BMP : PNG;
344 } 348 }
345 349
346 } 350 }
OLDNEW
« no previous file with comments | « Source/platform/image-decoders/ico/ICOImageDecoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698