OLD | NEW |
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, errorInPngInIco) { |
| 25 RefPtr<SharedBuffer> data = |
| 26 readFile("/LayoutTests/images/resources/png-in-ico.ico"); |
| 27 ASSERT_FALSE(data->isEmpty()); |
| 28 |
| 29 // Modify the file to have a broken CRC in IHDR. |
| 30 constexpr size_t crcOffset = 22 + 29; |
| 31 constexpr size_t crcSize = 4; |
| 32 RefPtr<SharedBuffer> modifiedData = |
| 33 SharedBuffer::create(data->data(), crcOffset); |
| 34 Vector<char> badCrc(crcSize, 0); |
| 35 modifiedData->append(badCrc); |
| 36 modifiedData->append(data->data() + crcOffset + crcSize, |
| 37 data->size() - crcOffset - crcSize); |
| 38 |
| 39 auto decoder = createDecoder(); |
| 40 decoder->setData(modifiedData.get(), true); |
| 41 |
| 42 // ICOImageDecoder reports the frame count based on whether enough data has |
| 43 // been received according to the icon directory. So even though the |
| 44 // embedded PNG is broken, there is enough data to include it in the frame |
| 45 // count. |
| 46 EXPECT_EQ(1u, decoder->frameCount()); |
| 47 |
| 48 decoder->frameBufferAtIndex(0); |
| 49 EXPECT_TRUE(decoder->failed()); |
| 50 } |
| 51 |
24 TEST(ICOImageDecoderTests, parseAndDecodeByteByByte) { | 52 TEST(ICOImageDecoderTests, parseAndDecodeByteByByte) { |
25 testByteByByteDecode(&createDecoder, | 53 testByteByByteDecode(&createDecoder, |
| 54 "/LayoutTests/images/resources/png-in-ico.ico", 1u, |
| 55 cAnimationNone); |
| 56 testByteByByteDecode(&createDecoder, |
26 "/LayoutTests/images/resources/2entries.ico", 2u, | 57 "/LayoutTests/images/resources/2entries.ico", 2u, |
27 cAnimationNone); | 58 cAnimationNone); |
28 testByteByByteDecode(&createDecoder, | 59 testByteByByteDecode(&createDecoder, |
29 "/LayoutTests/images/resources/greenbox-3frames.cur", 3u, | 60 "/LayoutTests/images/resources/greenbox-3frames.cur", 3u, |
30 cAnimationNone); | 61 cAnimationNone); |
31 testByteByByteDecode( | 62 testByteByByteDecode( |
32 &createDecoder, | 63 &createDecoder, |
33 "/LayoutTests/images/resources/icon-without-and-bitmap.ico", 1u, | 64 "/LayoutTests/images/resources/icon-without-and-bitmap.ico", 1u, |
34 cAnimationNone); | 65 cAnimationNone); |
35 testByteByByteDecode(&createDecoder, "/LayoutTests/images/resources/1bit.ico", | 66 testByteByByteDecode(&createDecoder, "/LayoutTests/images/resources/1bit.ico", |
36 1u, cAnimationNone); | 67 1u, cAnimationNone); |
37 testByteByByteDecode(&createDecoder, | 68 testByteByByteDecode(&createDecoder, |
38 "/LayoutTests/images/resources/bug653075.ico", 2u, | 69 "/LayoutTests/images/resources/bug653075.ico", 2u, |
39 cAnimationNone); | 70 cAnimationNone); |
40 } | 71 } |
41 | 72 |
42 } // namespace blink | 73 } // namespace blink |
OLD | NEW |