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 <array>
18 #include <cstddef>
19 #include <memory>
20 #include <utility>
21
DEF_TEST(BadImage,reporter)22 DEF_TEST(BadImage, reporter) {
23 const char* const badImages [] = {
24 "sigabort_favicon.ico",
25 "sigsegv_favicon.ico",
26 "sigsegv_favicon_2.ico",
27 "ico_leak01.ico",
28 "ico_fuzz0.ico",
29 "ico_fuzz1.ico",
30 "skbug3442.webp",
31 "skbug3429.webp",
32 "b38116746.ico",
33 "skbug5883.gif",
34 };
35
36 const char* badImagesFolder = "invalid_images";
37
38 for (size_t i = 0; i < std::size(badImages); ++i) {
39 SkString resourcePath = SkOSPath::Join(badImagesFolder, badImages[i]);
40 std::unique_ptr<SkStream> stream(GetResourceAsStream(resourcePath.c_str()));
41 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
42
43 // These images are corrupt. It's not important whether we succeed/fail in codec
44 // creation or decoding. We just want to make sure that we don't crash.
45 if (codec) {
46 SkBitmap bm;
47 bm.allocPixels(codec->getInfo());
48 codec->getPixels(codec->getInfo(), bm.getPixels(),
49 bm.rowBytes());
50 }
51 }
52 }
53