blob: e549b86b0b235b738dd1b44d313eb17c015423cb [file] [log] [blame]
scroggob61e2062014-11-10 13:12:25 -08001/*
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 "Resources.h"
scroggob61e2062014-11-10 13:12:25 -08009#include "SkBitmap.h"
msarett7f7ec202016-03-01 12:12:27 -080010#include "SkCodec.h"
Ben Wagnerbf111d72016-11-07 18:05:29 -050011#include "SkOSPath.h"
12#include "SkStream.h"
Ben Wagnere6b04a12018-03-09 14:41:36 -050013#include "SkString.h"
14#include "SkTypes.h"
15#include "Test.h"
16
17#include <memory>
18#include <utility>
scroggob61e2062014-11-10 13:12:25 -080019
scroggo139491f2015-07-10 09:32:09 -070020DEF_TEST(BadImage, reporter) {
21 const char* const badImages [] = {
scroggob61e2062014-11-10 13:12:25 -080022 "sigabort_favicon.ico",
23 "sigsegv_favicon.ico",
24 "sigsegv_favicon_2.ico",
msarett6e8f9032015-03-13 08:07:01 -070025 "ico_leak01.ico",
26 "ico_fuzz0.ico",
scroggo139491f2015-07-10 09:32:09 -070027 "ico_fuzz1.ico",
28 "skbug3442.webp",
29 "skbug3429.webp",
Leon Scroggins III12a4dc92017-06-05 14:06:57 -040030 "b38116746.ico",
scroggob61e2062014-11-10 13:12:25 -080031 };
32
scroggo139491f2015-07-10 09:32:09 -070033 const char* badImagesFolder = "invalid_images";
scroggob61e2062014-11-10 13:12:25 -080034
scroggo139491f2015-07-10 09:32:09 -070035 for (size_t i = 0; i < SK_ARRAY_COUNT(badImages); ++i) {
bungemanf93d7112016-09-16 06:24:20 -070036 SkString resourcePath = SkOSPath::Join(badImagesFolder, badImages[i]);
Ben Wagner145dbcd2016-11-03 14:40:50 -040037 std::unique_ptr<SkStream> stream(GetResourceAsStream(resourcePath.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -040038 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
msarett7f7ec202016-03-01 12:12:27 -080039
40 // These images are corrupt. It's not important whether we succeed/fail in codec
41 // creation or decoding. We just want to make sure that we don't crash.
42 if (codec) {
43 SkBitmap bm;
44 bm.allocPixels(codec->getInfo());
45 codec->getPixels(codec->getInfo(), bm.getPixels(),
46 bm.rowBytes());
47 }
scroggob61e2062014-11-10 13:12:25 -080048 }
49}