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

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

Issue 2761303003: Make ICO fail on truncated data (Closed)
Patch Set: Created 3 years, 9 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/image-decoders/ico/ICOImageDecoder.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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/image-decoders/ico/ICOImageDecoder.h" 5 #include "platform/image-decoders/ico/ICOImageDecoder.h"
6 6
7 #include "platform/image-decoders/ImageDecoderTestHelpers.h" 7 #include "platform/image-decoders/ImageDecoderTestHelpers.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "wtf/PtrUtil.h" 9 #include "wtf/PtrUtil.h"
10 #include <memory> 10 #include <memory>
11 11
12 namespace blink { 12 namespace blink {
13 13
14 namespace { 14 namespace {
15 15
16 std::unique_ptr<ImageDecoder> createDecoder() { 16 std::unique_ptr<ImageDecoder> createDecoder() {
17 return WTF::wrapUnique( 17 return WTF::wrapUnique(
18 new ICOImageDecoder(ImageDecoder::AlphaNotPremultiplied, 18 new ICOImageDecoder(ImageDecoder::AlphaNotPremultiplied,
19 ColorBehavior::transformToTargetForTesting(), 19 ColorBehavior::transformToTargetForTesting(),
20 ImageDecoder::noDecodedImageByteLimit)); 20 ImageDecoder::noDecodedImageByteLimit));
21 } 21 }
22 } 22 }
23 23
24 TEST(ICOImageDecoderTests, trunctedIco) {
25 RefPtr<SharedBuffer> data =
26 readFile("/LayoutTests/images/resources/png-in-ico.ico");
27 ASSERT_FALSE(data->isEmpty());
28
29 RefPtr<SharedBuffer> truncatedData =
30 SharedBuffer::create(data->data(), data->size() / 2);
31 auto decoder = createDecoder();
32
33 decoder->setData(truncatedData.get(), false);
34 decoder->frameBufferAtIndex(0);
35 EXPECT_FALSE(decoder->failed());
36
37 decoder->setData(truncatedData.get(), true);
38 decoder->frameBufferAtIndex(0);
39 EXPECT_TRUE(decoder->failed());
40 }
41
24 TEST(ICOImageDecoderTests, errorInPngInIco) { 42 TEST(ICOImageDecoderTests, errorInPngInIco) {
25 RefPtr<SharedBuffer> data = 43 RefPtr<SharedBuffer> data =
26 readFile("/LayoutTests/images/resources/png-in-ico.ico"); 44 readFile("/LayoutTests/images/resources/png-in-ico.ico");
27 ASSERT_FALSE(data->isEmpty()); 45 ASSERT_FALSE(data->isEmpty());
28 46
29 // Modify the file to have a broken CRC in IHDR. 47 // Modify the file to have a broken CRC in IHDR.
30 constexpr size_t crcOffset = 22 + 29; 48 constexpr size_t crcOffset = 22 + 29;
31 constexpr size_t crcSize = 4; 49 constexpr size_t crcSize = 4;
32 RefPtr<SharedBuffer> modifiedData = 50 RefPtr<SharedBuffer> modifiedData =
33 SharedBuffer::create(data->data(), crcOffset); 51 SharedBuffer::create(data->data(), crcOffset);
(...skipping 30 matching lines...) Expand all
64 "/LayoutTests/images/resources/icon-without-and-bitmap.ico", 1u, 82 "/LayoutTests/images/resources/icon-without-and-bitmap.ico", 1u,
65 cAnimationNone); 83 cAnimationNone);
66 testByteByByteDecode(&createDecoder, "/LayoutTests/images/resources/1bit.ico", 84 testByteByByteDecode(&createDecoder, "/LayoutTests/images/resources/1bit.ico",
67 1u, cAnimationNone); 85 1u, cAnimationNone);
68 testByteByByteDecode(&createDecoder, 86 testByteByByteDecode(&createDecoder,
69 "/LayoutTests/images/resources/bug653075.ico", 2u, 87 "/LayoutTests/images/resources/bug653075.ico", 2u,
70 cAnimationNone); 88 cAnimationNone);
71 } 89 }
72 90
73 } // namespace blink 91 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/image-decoders/ico/ICOImageDecoder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698