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

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

Issue 2173873003: Cancel image loads if decoding failed (attempt #2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix UAF Created 4 years, 5 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/image-decoders/ImageDecoder.h ('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 b3bd7d93278ee227f858d7c18dbbf28eacff334c..b45274cadd1c2e9b4c2724d300e7a0cd9bf33b94 100644
--- a/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp
@@ -80,49 +80,65 @@ inline bool matchesBMPSignature(const char* contents)
return !memcmp(contents, "BM", 2);
}
-std::unique_ptr<ImageDecoder> ImageDecoder::create(const char* contents, size_t length, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
+std::unique_ptr<ImageDecoder> ImageDecoder::create(SniffResult sniffResult, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
{
- const size_t longestSignatureLength = sizeof("RIFF????WEBPVP") - 1;
- ASSERT(longestSignatureLength == 14);
+ size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecodedImageBytes() : noDecodedImageByteLimit;
- if (length < longestSignatureLength)
+ switch (sniffResult) {
+ case SniffResult::JPEG:
+ return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
+ case SniffResult::PNG:
+ return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
+ case SniffResult::GIF:
+ return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
+ case SniffResult::WEBP:
+ return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
+ case SniffResult::ICO:
+ return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
+ case SniffResult::BMP:
+ return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
+ case SniffResult::InsufficientData:
+ case SniffResult::Invalid:
return nullptr;
+ }
+ NOTREACHED();
+ return nullptr;
+}
- size_t maxDecodedBytes = Platform::current() ? Platform::current()->maxDecodedImageBytes() : noDecodedImageByteLimit;
+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)
+ return SniffResult::InsufficientData;
if (matchesJPEGSignature(contents))
- return wrapUnique(new JPEGImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
-
+ return SniffResult::JPEG;
if (matchesPNGSignature(contents))
- return wrapUnique(new PNGImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
-
+ return SniffResult::PNG;
if (matchesGIFSignature(contents))
- return wrapUnique(new GIFImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
-
+ return SniffResult::GIF;
if (matchesWebPSignature(contents))
- return wrapUnique(new WEBPImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
-
+ return SniffResult::WEBP;
if (matchesICOSignature(contents) || matchesCURSignature(contents))
- return wrapUnique(new ICOImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
-
+ return SniffResult::ICO;
if (matchesBMPSignature(contents))
- return wrapUnique(new BMPImageDecoder(alphaOption, colorOptions, maxDecodedBytes));
-
- return nullptr;
+ return SniffResult::BMP;
+ return SniffResult::Invalid;
}
-std::unique_ptr<ImageDecoder> ImageDecoder::create(const SharedBuffer& data, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
+ImageDecoder::SniffResult ImageDecoder::determineImageType(const SharedBuffer& data)
{
const char* contents;
const size_t length = data.getSomeData<size_t>(contents);
- return create(contents, length, alphaOption, colorOptions);
+ return determineImageType(contents, length);
}
-std::unique_ptr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOption alphaOption, GammaAndColorProfileOption colorOptions)
+ImageDecoder::SniffResult ImageDecoder::determineImageType(const SegmentReader& data)
{
const char* contents;
const size_t length = data.getSomeData(contents, 0);
- return create(contents, length, alphaOption, colorOptions);
+ return determineImageType(contents, length);
}
size_t ImageDecoder::frameCount()
« no previous file with comments | « third_party/WebKit/Source/platform/image-decoders/ImageDecoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698