Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
BadIcoTest.cpp
Go to the documentation of this file.
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
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
22DEF_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}
reporter
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
Definition Resources.cpp:31
#define DEF_TEST(name, reporter)
Definition Test.h:312
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
size_t rowBytes() const
Definition SkBitmap.h:238
void * getPixels() const
Definition SkBitmap.h:283
static std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream >, SkSpan< const SkCodecs::Decoder > decoders, Result *=nullptr, SkPngChunkReader *=nullptr, SelectionPolicy selectionPolicy=SelectionPolicy::kPreferStillImage)
Definition SkCodec.cpp:163
static SkString Join(const char *rootPath, const char *relativePath)
Definition SkOSPath.cpp:14
const char * c_str() const
Definition SkString.h:133