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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTestWoPlatform.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
diff --git a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
index 874b7d06e12a3f288ac7c7d56ac845b6f1a6bcfa..edf80d2fbbe5c151122cfbd9b8d4e7d5e5a82c46 100644
--- a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
@@ -23,6 +23,7 @@
#include "platform/PlatformInstrumentation.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "platform/graphics/BitmapImageMetrics.h"
+#include "platform/image-decoders/FastSharedBufferReader.h"
#include "platform/image-decoders/bmp/BMPImageDecoder.h"
#include "platform/image-decoders/gif/GIFImageDecoder.h"
#include "platform/image-decoders/ico/ICOImageDecoder.h"
@@ -107,12 +108,16 @@ std::unique_ptr<ImageDecoder> ImageDecoder::create(SniffResult sniffResult, Alph
return nullptr;
}
+namespace {
+
+// This needs to be updated if we ever add a matches*Signature() which requires more characters.
+constexpr size_t kLongestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
+
+} // anonymous ns
+
ImageDecoder::SniffResult ImageDecoder::determineImageType(const char* contents, size_t length)
{
- const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
- DCHECK_EQ(14u, longestSignatureLength);
-
- if (length < longestSignatureLength)
+ if (length < kLongestSignatureLength)
return SniffResult::InsufficientData;
if (matchesJPEGSignature(contents))
return SniffResult::JPEG;
@@ -131,16 +136,20 @@ ImageDecoder::SniffResult ImageDecoder::determineImageType(const char* contents,
ImageDecoder::SniffResult ImageDecoder::determineImageType(const SharedBuffer& data)
{
- const char* contents;
- const size_t length = data.getSomeData<size_t>(contents);
- return determineImageType(contents, length);
+ // TODO(fmalita): refactor the method signature to avoid casting.
+ RefPtr<SegmentReader> reader = SegmentReader::createFromSharedBuffer(const_cast<SharedBuffer*>(&data));
+
+ return determineImageType(*reader);
}
ImageDecoder::SniffResult ImageDecoder::determineImageType(const SegmentReader& data)
{
- const char* contents;
- const size_t length = data.getSomeData(contents, 0);
- return determineImageType(contents, length);
+ // TODO(fmalita): refactor the method signature to avoid casting.
+ const FastSharedBufferReader fastReader(const_cast<SegmentReader*>(&data));
+ char buffer[kLongestSignatureLength];
+ const size_t len = std::min(kLongestSignatureLength, data.size());
+
+ return determineImageType(fastReader.getConsecutiveData(0, len, buffer), len);
}
size_t ImageDecoder::frameCount()
« 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