| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 if ((m_decodedOffset < sizeOfDirectory) && !processDirectory()) | 182 if ((m_decodedOffset < sizeOfDirectory) && !processDirectory()) |
| 183 return false; | 183 return false; |
| 184 | 184 |
| 185 // Read and process directory entries. | 185 // Read and process directory entries. |
| 186 return (m_decodedOffset >= | 186 return (m_decodedOffset >= |
| 187 (sizeOfDirectory + (m_dirEntriesCount * sizeOfDirEntry))) || | 187 (sizeOfDirectory + (m_dirEntriesCount * sizeOfDirEntry))) || |
| 188 processDirectoryEntries(); | 188 processDirectoryEntries(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 bool ICOImageDecoder::decodeAtIndex(size_t index) { | 191 bool ICOImageDecoder::decodeAtIndex(size_t index) { |
| 192 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); | 192 SECURITY_DCHECK(index < m_dirEntries.size()); |
| 193 const IconDirectoryEntry& dirEntry = m_dirEntries[index]; | 193 const IconDirectoryEntry& dirEntry = m_dirEntries[index]; |
| 194 const ImageType imageType = imageTypeAtIndex(index); | 194 const ImageType imageType = imageTypeAtIndex(index); |
| 195 if (imageType == Unknown) | 195 if (imageType == Unknown) |
| 196 return false; // Not enough data to determine image type yet. | 196 return false; // Not enough data to determine image type yet. |
| 197 | 197 |
| 198 if (imageType == BMP) { | 198 if (imageType == BMP) { |
| 199 if (!m_bmpReaders[index]) { | 199 if (!m_bmpReaders[index]) { |
| 200 m_bmpReaders[index] = | 200 m_bmpReaders[index] = |
| 201 wrapUnique(new BMPImageReader(this, dirEntry.m_imageOffset, 0, true)); | 201 wrapUnique(new BMPImageReader(this, dirEntry.m_imageOffset, 0, true)); |
| 202 m_bmpReaders[index]->setData(m_data.get()); | 202 m_bmpReaders[index]->setData(m_data.get()); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 ++entry.m_bitCount; | 323 ++entry.m_bitCount; |
| 324 } | 324 } |
| 325 | 325 |
| 326 m_decodedOffset += sizeOfDirEntry; | 326 m_decodedOffset += sizeOfDirEntry; |
| 327 return entry; | 327 return entry; |
| 328 } | 328 } |
| 329 | 329 |
| 330 ICOImageDecoder::ImageType ICOImageDecoder::imageTypeAtIndex(size_t index) { | 330 ICOImageDecoder::ImageType ICOImageDecoder::imageTypeAtIndex(size_t index) { |
| 331 // Check if this entry is a BMP or a PNG; we need 4 bytes to check the magic | 331 // Check if this entry is a BMP or a PNG; we need 4 bytes to check the magic |
| 332 // number. | 332 // number. |
| 333 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); | 333 SECURITY_DCHECK(index < m_dirEntries.size()); |
| 334 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; | 334 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; |
| 335 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) | 335 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) |
| 336 return Unknown; | 336 return Unknown; |
| 337 char buffer[4]; | 337 char buffer[4]; |
| 338 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); | 338 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); |
| 339 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; | 339 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; |
| 340 } | 340 } |
| 341 | 341 |
| 342 } // namespace blink | 342 } // namespace blink |
| OLD | NEW |