1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "include/codec/SkCodec.h"
9 #include "include/core/SkBitmap.h"
10 #include "include/core/SkStream.h"
11 #include "include/core/SkString.h"
12 #include "include/core/SkTypes.h"
13 #include "src/utils/SkOSPath.h"
14 #include "tests/Test.h"
15 #include "tools/Resources.h"
16 
17 #include <memory>
18 #include <utility>
19 
DEF_TEST(BadImage,reporter)20 DEF_TEST(BadImage, reporter) {
21     const char* const badImages [] = {
22         "sigabort_favicon.ico",
23         "sigsegv_favicon.ico",
24         "sigsegv_favicon_2.ico",
25         "ico_leak01.ico",
26         "ico_fuzz0.ico",
27         "ico_fuzz1.ico",
28         "skbug3442.webp",
29         "skbug3429.webp",
30         "b38116746.ico",
31         "skbug5883.gif",
32     };
33 
34     const char* badImagesFolder = "invalid_images";
35 
36     for (size_t i = 0; i < SK_ARRAY_COUNT(badImages); ++i) {
37         SkString resourcePath = SkOSPath::Join(badImagesFolder, badImages[i]);
38         std::unique_ptr<SkStream> stream(GetResourceAsStream(resourcePath.c_str()));
39         std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
40 
41         // These images are corrupt.  It's not important whether we succeed/fail in codec
42         // creation or decoding.  We just want to make sure that we don't crash.
43         if (codec) {
44             SkBitmap bm;
45             bm.allocPixels(codec->getInfo());
46             codec->getPixels(codec->getInfo(), bm.getPixels(),
47                     bm.rowBytes());
48         }
49     }
50 }
51