Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 RefPtr<SharedBuffer> bmpData(SharedBuffer::create(&m_data->data()[di rEntry.m_imageOffset], dirEntry.m_imageSize)); |
| 220 m_bmpReaders[index]->setData(m_data.get()); | 220 m_bmpReaders[index] = adoptPtr(new BMPImageReader(this, 0, 0, true)) ; |
| 221 m_bmpReaders[index]->setData(bmpData.get()); | |
| 221 m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]); | 222 m_bmpReaders[index]->setBuffer(&m_frameBufferCache[index]); |
| 222 } | 223 } |
| 223 m_frameSize = dirEntry.m_size; | 224 m_frameSize = dirEntry.m_size; |
| 224 bool result = m_bmpReaders[index]->decodeBMP(false); | 225 bool result = m_bmpReaders[index]->decodeBMP(false); |
| 225 m_frameSize = IntSize(); | 226 m_frameSize = IntSize(); |
| 226 return result; | 227 return result; |
| 227 } | 228 } |
| 228 | 229 |
| 229 if (!m_pngDecoders[index]) { | 230 if (!m_pngDecoders[index]) { |
| 230 m_pngDecoders[index] = adoptPtr( | 231 m_pngDecoders[index] = adoptPtr( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 height = 256; | 308 height = 256; |
| 308 IconDirectoryEntry entry; | 309 IconDirectoryEntry entry; |
| 309 entry.m_size = IntSize(width, height); | 310 entry.m_size = IntSize(width, height); |
| 310 if (m_fileType == CURSOR) { | 311 if (m_fileType == CURSOR) { |
| 311 entry.m_bitCount = 0; | 312 entry.m_bitCount = 0; |
| 312 entry.m_hotSpot = IntPoint(readUint16(4), readUint16(6)); | 313 entry.m_hotSpot = IntPoint(readUint16(4), readUint16(6)); |
| 313 } else { | 314 } else { |
| 314 entry.m_bitCount = readUint16(6); | 315 entry.m_bitCount = readUint16(6); |
| 315 entry.m_hotSpot = IntPoint(); | 316 entry.m_hotSpot = IntPoint(); |
| 316 } | 317 } |
| 318 entry.m_imageSize = readUint32(8); | |
|
Stephen White
2014/11/17 20:43:05
I'm probably just showing my ignorance of this cod
| |
| 317 entry.m_imageOffset = readUint32(12); | 319 entry.m_imageOffset = readUint32(12); |
| 318 | 320 |
| 321 // Make sure the image data doesn't go beyond the end of the file. | |
| 322 entry.m_imageSize = std::min(entry.m_imageSize, m_data->size() - entry.m_ima geOffset); | |
| 323 | |
| 319 // Some icons don't have a bit depth, only a color count. Convert the | 324 // 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 | 325 // 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 | 326 // 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. | 327 // this value to determine which icon entry is best. |
| 323 if (!entry.m_bitCount) { | 328 if (!entry.m_bitCount) { |
| 324 int colorCount = static_cast<uint8_t>(m_data->data()[m_decodedOffset + 2 ]); | 329 int colorCount = static_cast<uint8_t>(m_data->data()[m_decodedOffset + 2 ]); |
| 325 if (!colorCount) | 330 if (!colorCount) |
| 326 colorCount = 256; // Vague in the spec, needed by real-world icons. | 331 colorCount = 256; // Vague in the spec, needed by real-world icons. |
| 327 for (--colorCount; colorCount; colorCount >>= 1) | 332 for (--colorCount; colorCount; colorCount >>= 1) |
| 328 ++entry.m_bitCount; | 333 ++entry.m_bitCount; |
| 329 } | 334 } |
| 330 | 335 |
| 331 m_decodedOffset += sizeOfDirEntry; | 336 m_decodedOffset += sizeOfDirEntry; |
| 332 return entry; | 337 return entry; |
| 333 } | 338 } |
| 334 | 339 |
| 335 ICOImageDecoder::ImageType ICOImageDecoder::imageTypeAtIndex(size_t index) | 340 ICOImageDecoder::ImageType ICOImageDecoder::imageTypeAtIndex(size_t index) |
| 336 { | 341 { |
| 337 // Check if this entry is a BMP or a PNG; we need 4 bytes to check the magic | 342 // Check if this entry is a BMP or a PNG; we need 4 bytes to check the magic |
| 338 // number. | 343 // number. |
| 339 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); | 344 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); |
| 340 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; | 345 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; |
| 341 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) | 346 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) |
| 342 return Unknown; | 347 return Unknown; |
| 343 return strncmp(&m_data->data()[imageOffset], "\x89PNG", 4) ? BMP : PNG; | 348 return strncmp(&m_data->data()[imageOffset], "\x89PNG", 4) ? BMP : PNG; |
| 344 } | 349 } |
| 345 | 350 |
| 346 } | 351 } |
| OLD | NEW |