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

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

Issue 2260703002: Fix fragmented image signature handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: 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 | « no previous file | 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 b3bd7d93278ee227f858d7c18dbbf28eacff334c..a393b9c5fd60359add71919e743b00237d746ac0 100644
--- a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
@@ -21,6 +21,7 @@
#include "platform/image-decoders/ImageDecoder.h"
#include "platform/PlatformInstrumentation.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"
@@ -80,12 +81,16 @@ inline bool matchesBMPSignature(const char* contents)
return !memcmp(contents, "BM", 2);
}
+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
+
std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
{
- const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
- ASSERT(longestSignatureLength == 14);
-
- if (length < longestSignatureLength)
+ if (length < kLongestSignatureLength)
return nullptr;
size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecodedImageBytes() : noDecodedImageByteLimit;
@@ -113,16 +118,17 @@ std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t
std::unique_ptr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
{
- const char* contents;
- const size_t length = data.getSomeData<size_t>(contents);
- return create(contents, length, alphaOption, colorOptions);
+ RefPtr<SegmentReader> reader = SegmentReader::createFromSharedBuffer(const_cast<SharedBuffer*>(&data));
+ return create(*reader, alphaOption, colorOptions);
}
std::unique_ptr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
{
- const char* contents;
- const size_t length = data.getSomeData(contents, 0);
- return create(contents, length, alphaOption, colorOptions);
+ const FastSharedBufferReader fastReader(const_cast<SegmentReader*>(&data));
+ char buffer[kLongestSignatureLength];
+ const size_t len = std::min(kLongestSignatureLength, data.size());
+
+ return create(fastReader.getConsecutiveData(0, len, buffer), len, alphaOption, colorOptions);
}
size_t ImageDecoder::frameCount()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698