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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp

Issue 2252723003: Fix fragmented image signature handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: replace useless assert with a comment Created 4 years, 4 months 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTestWoPlatform.cpp ('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) Research In Motion Limited 2009-2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 * 18 *
19 */ 19 */
20 20
21 #include "platform/image-decoders/ImageDecoder.h" 21 #include "platform/image-decoders/ImageDecoder.h"
22 22
23 #include "platform/PlatformInstrumentation.h" 23 #include "platform/PlatformInstrumentation.h"
24 #include "platform/RuntimeEnabledFeatures.h" 24 #include "platform/RuntimeEnabledFeatures.h"
25 #include "platform/graphics/BitmapImageMetrics.h" 25 #include "platform/graphics/BitmapImageMetrics.h"
26 #include "platform/image-decoders/FastSharedBufferReader.h"
26 #include "platform/image-decoders/bmp/BMPImageDecoder.h" 27 #include "platform/image-decoders/bmp/BMPImageDecoder.h"
27 #include "platform/image-decoders/gif/GIFImageDecoder.h" 28 #include "platform/image-decoders/gif/GIFImageDecoder.h"
28 #include "platform/image-decoders/ico/ICOImageDecoder.h" 29 #include "platform/image-decoders/ico/ICOImageDecoder.h"
29 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h" 30 #include "platform/image-decoders/jpeg/JPEGImageDecoder.h"
30 #include "platform/image-decoders/png/PNGImageDecoder.h" 31 #include "platform/image-decoders/png/PNGImageDecoder.h"
31 #include "platform/image-decoders/webp/WEBPImageDecoder.h" 32 #include "platform/image-decoders/webp/WEBPImageDecoder.h"
32 #include "wtf/PtrUtil.h" 33 #include "wtf/PtrUtil.h"
33 #include <memory> 34 #include <memory>
34 35
35 namespace blink { 36 namespace blink {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 case SniffResult::BMP: 101 case SniffResult::BMP:
101 return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDeco dedBytes)); 102 return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDeco dedBytes));
102 case SniffResult::InsufficientData: 103 case SniffResult::InsufficientData:
103 case SniffResult::Invalid: 104 case SniffResult::Invalid:
104 return nullptr; 105 return nullptr;
105 } 106 }
106 NOTREACHED(); 107 NOTREACHED();
107 return nullptr; 108 return nullptr;
108 } 109 }
109 110
111 namespace {
112
113 // This needs to be updated if we ever add a matches*Signature() which requires more characters.
114 constexpr size_t kLongestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
115
116 } // anonymous ns
117
110 ImageDecoder::SniffResult ImageDecoder::determineImageType(const char* contents, size_t length) 118 ImageDecoder::SniffResult ImageDecoder::determineImageType(const char* contents, size_t length)
111 { 119 {
112 const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1; 120 if (length < kLongestSignatureLength)
113 DCHECK_EQ(14u, longestSignatureLength);
114
115 if (length < longestSignatureLength)
116 return SniffResult::InsufficientData; 121 return SniffResult::InsufficientData;
117 if (matchesJPEGSignature(contents)) 122 if (matchesJPEGSignature(contents))
118 return SniffResult::JPEG; 123 return SniffResult::JPEG;
119 if (matchesPNGSignature(contents)) 124 if (matchesPNGSignature(contents))
120 return SniffResult::PNG; 125 return SniffResult::PNG;
121 if (matchesGIFSignature(contents)) 126 if (matchesGIFSignature(contents))
122 return SniffResult::GIF; 127 return SniffResult::GIF;
123 if (matchesWebPSignature(contents)) 128 if (matchesWebPSignature(contents))
124 return SniffResult::WEBP; 129 return SniffResult::WEBP;
125 if (matchesICOSignature(contents) || matchesCURSignature(contents)) 130 if (matchesICOSignature(contents) || matchesCURSignature(contents))
126 return SniffResult::ICO; 131 return SniffResult::ICO;
127 if (matchesBMPSignature(contents)) 132 if (matchesBMPSignature(contents))
128 return SniffResult::BMP; 133 return SniffResult::BMP;
129 return SniffResult::Invalid; 134 return SniffResult::Invalid;
130 } 135 }
131 136
132 ImageDecoder::SniffResult ImageDecoder::determineImageType(const SharedBuffer& d ata) 137 ImageDecoder::SniffResult ImageDecoder::determineImageType(const SharedBuffer& d ata)
133 { 138 {
134 const char* contents; 139 // TODO(fmalita): refactor the method signature to avoid casting.
135 const size_t length = data.getSomeData<size_t>(contents); 140 RefPtr<SegmentReader> reader = SegmentReader::createFromSharedBuffer(const_c ast<SharedBuffer*>(&data));
136 return determineImageType(contents, length); 141
142 return determineImageType(*reader);
137 } 143 }
138 144
139 ImageDecoder::SniffResult ImageDecoder::determineImageType(const SegmentReader& data) 145 ImageDecoder::SniffResult ImageDecoder::determineImageType(const SegmentReader& data)
140 { 146 {
141 const char* contents; 147 // TODO(fmalita): refactor the method signature to avoid casting.
142 const size_t length = data.getSomeData(contents, 0); 148 const FastSharedBufferReader fastReader(const_cast<SegmentReader*>(&data));
143 return determineImageType(contents, length); 149 char buffer[kLongestSignatureLength];
150 const size_t len = std::min(kLongestSignatureLength, data.size());
151
152 return determineImageType(fastReader.getConsecutiveData(0, len, buffer), len );
144 } 153 }
145 154
146 size_t ImageDecoder::frameCount() 155 size_t ImageDecoder::frameCount()
147 { 156 {
148 const size_t oldSize = m_frameBufferCache.size(); 157 const size_t oldSize = m_frameBufferCache.size();
149 const size_t newSize = decodeFrameCount(); 158 const size_t newSize = decodeFrameCount();
150 if (oldSize != newSize) { 159 if (oldSize != newSize) {
151 m_frameBufferCache.resize(newSize); 160 m_frameBufferCache.resize(newSize);
152 for (size_t i = oldSize; i < newSize; ++i) { 161 for (size_t i = oldSize; i < newSize; ++i) {
153 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); 162 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 return; 414 return;
406 415
407 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; 416 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8;
408 417
409 // FIXME: Don't force perceptual intent if the image profile contains an int ent. 418 // FIXME: Don't force perceptual intent if the image profile contains an int ent.
410 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil e.get(), dataFormat, gTargetColorProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTU AL)); 419 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil e.get(), dataFormat, gTargetColorProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTU AL));
411 #endif // USE(QCMSLIB) 420 #endif // USE(QCMSLIB)
412 } 421 }
413 422
414 } // namespace blink 423 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTestWoPlatform.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698