blob: 21343a2a5cd48663e0616b3bafa9d231b1c918ac [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"
9#include "Test.h"
Ben Wagnerbf111d72016-11-07 18:05:29 -050010
scroggob61e2062014-11-10 13:12:25 -080011#include "SkBitmap.h"
msarett7f7ec202016-03-01 12:12:27 -080012#include "SkCodec.h"
scroggob61e2062014-11-10 13:12:25 -080013#include "SkOSFile.h"
Ben Wagnerbf111d72016-11-07 18:05:29 -050014#include "SkOSPath.h"
15#include "SkStream.h"
scroggob61e2062014-11-10 13:12:25 -080016
scroggo139491f2015-07-10 09:32:09 -070017DEF_TEST(BadImage, reporter) {
18 const char* const badImages [] = {
scroggob61e2062014-11-10 13:12:25 -080019 "sigabort_favicon.ico",
20 "sigsegv_favicon.ico",
21 "sigsegv_favicon_2.ico",
msarett6e8f9032015-03-13 08:07:01 -070022 "ico_leak01.ico",
23 "ico_fuzz0.ico",
scroggo139491f2015-07-10 09:32:09 -070024 "ico_fuzz1.ico",
25 "skbug3442.webp",
26 "skbug3429.webp",
Leon Scroggins III12a4dc92017-06-05 14:06:57 -040027 "b38116746.ico",
scroggob61e2062014-11-10 13:12:25 -080028 };
29
scroggo139491f2015-07-10 09:32:09 -070030 const char* badImagesFolder = "invalid_images";
scroggob61e2062014-11-10 13:12:25 -080031
scroggo139491f2015-07-10 09:32:09 -070032 for (size_t i = 0; i < SK_ARRAY_COUNT(badImages); ++i) {
bungemanf93d7112016-09-16 06:24:20 -070033 SkString resourcePath = SkOSPath::Join(badImagesFolder, badImages[i]);
Ben Wagner145dbcd2016-11-03 14:40:50 -040034 std::unique_ptr<SkStream> stream(GetResourceAsStream(resourcePath.c_str()));
Mike Reedede7bac2017-07-23 15:30:02 -040035 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
msarett7f7ec202016-03-01 12:12:27 -080036
37 // These images are corrupt. It's not important whether we succeed/fail in codec
38 // creation or decoding. We just want to make sure that we don't crash.
39 if (codec) {
40 SkBitmap bm;
41 bm.allocPixels(codec->getInfo());
42 codec->getPixels(codec->getInfo(), bm.getPixels(),
43 bm.rowBytes());
44 }
scroggob61e2062014-11-10 13:12:25 -080045 }
46}