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

Unified Diff: third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTestWoPlatform.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 | « no previous file | third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTestWoPlatform.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTestWoPlatform.cpp b/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTestWoPlatform.cpp
index 10887c1afbe5e759442f14486dbaebff67ab1e44..48faa2a32c499ed71ecbe23f404db875e75de2f2 100644
--- a/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTestWoPlatform.cpp
+++ b/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTestWoPlatform.cpp
@@ -80,4 +80,36 @@ TEST(DeferredImageDecoderTestWoPlatform, mixImagesIco)
mixImages("/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico", 1376u, 1u);
}
+TEST(DeferredImageDecoderTestWoPlatform, fragmentedSignature)
+{
+ struct {
+ const char* m_file;
+ ImageDecoder::SniffResult m_expectedResult;
+ } tests[] = {
+ { "/LayoutTests/fast/images/resources/animated.gif", ImageDecoder::SniffResult::GIF },
+ { "/LayoutTests/fast/images/resources/mu.png", ImageDecoder::SniffResult::PNG },
+ { "/LayoutTests/fast/images/resources/2-dht.jpg", ImageDecoder::SniffResult::JPEG },
+ { "/LayoutTests/fast/images/resources/webp-animated.webp", ImageDecoder::SniffResult::WEBP },
+ { "/LayoutTests/fast/images/resources/lenna.bmp", ImageDecoder::SniffResult::BMP },
+ { "/LayoutTests/fast/images/resources/wrong-frame-dimensions.ico", ImageDecoder::SniffResult::ICO },
+ };
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(tests); ++i) {
+ RefPtr<SharedBuffer> fileBuffer = readFile(tests[i].m_file);
+ ASSERT_NE(fileBuffer, nullptr);
+ // We need contiguous data, which SharedBuffer doesn't guarantee.
+ sk_sp<SkData> skData = fileBuffer->getAsSkData();
+ ASSERT_EQ(skData->size(), fileBuffer->size());
+ const char* data = reinterpret_cast<const char*>(skData->bytes());
+
+ // Truncated signature (only 1 byte)
+ RefPtr<SharedBuffer> buffer = SharedBuffer::create<size_t>(data, 1u);
+ ASSERT_EQ(ImageDecoder::determineImageType(*buffer), ImageDecoder::SniffResult::InsufficientData);
+
+ // Append the rest of the data. We should be able to sniff the signature now, even if segmented.
+ buffer->append<size_t>(data + 1, skData->size() - 1);
+ ASSERT_EQ(ImageDecoder::determineImageType(*buffer), tests[i].m_expectedResult);
+ }
+}
+
} // namespace blink
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698