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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 return (aEntryArea == bEntryArea) ? (a.m_bitCount > b.m_bitCount) : (aEntryA rea > bEntryArea); | 126 return (aEntryArea == bEntryArea) ? (a.m_bitCount > b.m_bitCount) : (aEntryA rea > bEntryArea); |
| 127 } | 127 } |
| 128 | 128 |
| 129 size_t ICOImageDecoder::decodeFrameCount() | 129 size_t ICOImageDecoder::decodeFrameCount() |
| 130 { | 130 { |
| 131 decodeSize(); | 131 decodeSize(); |
| 132 | 132 |
| 133 // If decodeSize() fails, return the existing number of frames. This way | 133 // If decodeSize() fails, return the existing number of frames. This way |
| 134 // if we get halfway through the image before decoding fails, we won't | 134 // if we get halfway through the image before decoding fails, we won't |
| 135 // suddenly start reporting that the image has zero frames. | 135 // suddenly start reporting that the image has zero frames. |
| 136 if (failed()) | 136 if (failed()) |
|
aleksandar.stojiljkovic
2016/06/20 23:30:24
It relates to the part explained bellow and usage
Peter Kasting
2016/06/20 23:35:47
I still don't understand. If we successfully deco
aleksandar.stojiljkovic
2016/06/20 23:58:39
I am not sure when the situation could happen outs
Peter Kasting
2016/06/21 00:08:56
It seems like if the test is calling setData() on
aleksandar.stojiljkovic
2016/06/21 10:34:44
You're right. This is not the fix.
After further c
| |
| 137 return m_frameBufferCache.size(); | 137 return m_frameBufferCache.size(); |
| 138 | 138 |
| 139 // Length of sequence of completely received frames. | 139 // Length of sequence of completely received frames. |
| 140 for (size_t i = 0; i < m_dirEntries.size(); ++i) { | 140 for (size_t i = 0; i < m_dirEntries.size(); ++i) { |
| 141 const IconDirectoryEntry& dirEntry = m_dirEntries[i]; | 141 const IconDirectoryEntry& dirEntry = m_dirEntries[i]; |
| 142 if ((dirEntry.m_imageOffset + dirEntry.m_byteSize) > m_data->size()) | 142 if ((dirEntry.m_imageOffset + dirEntry.m_byteSize) > m_data->size()) |
| 143 return i; | 143 return i; |
| 144 } | 144 } |
| 145 return m_dirEntries.size(); | 145 return m_dirEntries.size(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void ICOImageDecoder::setDataForPNGDecoderAtIndex(size_t index) | 148 void ICOImageDecoder::setDataForPNGDecoderAtIndex(size_t index) |
| 149 { | 149 { |
| 150 if (!m_pngDecoders[index]) | 150 if (!m_pngDecoders[index]) |
| 151 return; | 151 return; |
| 152 | 152 |
| 153 m_pngDecoders[index]->setData(m_data.get(), isAllDataReceived()); | 153 m_pngDecoders[index]->setData(m_data.get(), isAllDataReceived()); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void ICOImageDecoder::decode(size_t index, bool onlySize) | 156 void ICOImageDecoder::decode(size_t index, bool onlySize) |
| 157 { | 157 { |
| 158 if (failed()) | 158 if (failed()) |
| 159 return; | 159 return; |
| 160 | 160 |
| 161 // Defensively clear the FastSharedBufferReader's cache, as another caller | 161 // Defensively clear the FastSharedBufferReader's cache, as another caller |
| 162 // may have called SharedBuffer::mergeSegmentsIntoBuffer(). | 162 // may have called SharedBuffer::mergeSegmentsIntoBuffer(). |
| 163 m_fastReader.clearCache(); | 163 m_fastReader.clearCache(); |
| 164 | 164 |
| 165 // If we couldn't decode the image but we've received all the data, decoding | 165 // If we couldn't decode the image or the data was truncated but we've |
| 166 // has failed. | 166 // received all the data, decoding has failed. |
| 167 if ((!decodeDirectory() || (!onlySize && !decodeAtIndex(index))) && isAllDat aReceived()) { | 167 if ((!decodeDirectory() || m_data->size() < m_decodedOffset || (!onlySize && !decodeAtIndex(index))) && isAllDataReceived()) { |
|
Peter Kasting
2016/06/20 23:08:03
Why do we want this behavior?
If we're not trying
aleksandar.stojiljkovic
2016/06/20 23:30:24
I have put explanation above, in decodeFrameCount
| |
| 168 setFailed(); | 168 setFailed(); |
| 169 // If we're done decoding this frame, we don't need the BMPImageReader or | 169 // If we're done decoding this frame, we don't need the BMPImageReader or |
| 170 // PNGImageDecoder anymore. (If we failed, these have already been | 170 // PNGImageDecoder anymore. (If we failed, these have already been |
| 171 // cleared.) | 171 // cleared.) |
| 172 } else if ((m_frameBufferCache.size() > index) && (m_frameBufferCache[index] .getStatus() == ImageFrame::FrameComplete)) { | 172 } else if ((m_frameBufferCache.size() > index) && (m_frameBufferCache[index] .getStatus() == ImageFrame::FrameComplete)) { |
| 173 m_bmpReaders[index].reset(); | 173 m_bmpReaders[index].reset(); |
| 174 m_pngDecoders[index].reset(); | 174 m_pngDecoders[index].reset(); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); | 325 ASSERT_WITH_SECURITY_IMPLICATION(index < m_dirEntries.size()); |
| 326 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; | 326 const uint32_t imageOffset = m_dirEntries[index].m_imageOffset; |
| 327 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) | 327 if ((imageOffset > m_data->size()) || ((m_data->size() - imageOffset) < 4)) |
| 328 return Unknown; | 328 return Unknown; |
| 329 char buffer[4]; | 329 char buffer[4]; |
| 330 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); | 330 const char* data = m_fastReader.getConsecutiveData(imageOffset, 4, buffer); |
| 331 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; | 331 return strncmp(data, "\x89PNG", 4) ? BMP : PNG; |
| 332 } | 332 } |
| 333 | 333 |
| 334 } // namespace blink | 334 } // namespace blink |
| OLD | NEW |