scroggo | b61e206 | 2014-11-10 13:12:25 -0800 | [diff] [blame] | 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 "Resources.h" |
| 9 | #include "Test.h" |
Ben Wagner | bf111d7 | 2016-11-07 18:05:29 -0500 | [diff] [blame] | 10 | |
scroggo | b61e206 | 2014-11-10 13:12:25 -0800 | [diff] [blame] | 11 | #include "SkBitmap.h" |
msarett | 7f7ec20 | 2016-03-01 12:12:27 -0800 | [diff] [blame] | 12 | #include "SkCodec.h" |
scroggo | b61e206 | 2014-11-10 13:12:25 -0800 | [diff] [blame] | 13 | #include "SkOSFile.h" |
Ben Wagner | bf111d7 | 2016-11-07 18:05:29 -0500 | [diff] [blame] | 14 | #include "SkOSPath.h" |
| 15 | #include "SkStream.h" |
scroggo | b61e206 | 2014-11-10 13:12:25 -0800 | [diff] [blame] | 16 | |
scroggo | 139491f | 2015-07-10 09:32:09 -0700 | [diff] [blame] | 17 | DEF_TEST(BadImage, reporter) { |
| 18 | const char* const badImages [] = { |
scroggo | b61e206 | 2014-11-10 13:12:25 -0800 | [diff] [blame] | 19 | "sigabort_favicon.ico", |
| 20 | "sigsegv_favicon.ico", |
| 21 | "sigsegv_favicon_2.ico", |
msarett | 6e8f903 | 2015-03-13 08:07:01 -0700 | [diff] [blame] | 22 | "ico_leak01.ico", |
| 23 | "ico_fuzz0.ico", |
scroggo | 139491f | 2015-07-10 09:32:09 -0700 | [diff] [blame] | 24 | "ico_fuzz1.ico", |
| 25 | "skbug3442.webp", |
| 26 | "skbug3429.webp", |
Leon Scroggins III | 12a4dc9 | 2017-06-05 14:06:57 -0400 | [diff] [blame] | 27 | "b38116746.ico", |
scroggo | b61e206 | 2014-11-10 13:12:25 -0800 | [diff] [blame] | 28 | }; |
| 29 | |
scroggo | 139491f | 2015-07-10 09:32:09 -0700 | [diff] [blame] | 30 | const char* badImagesFolder = "invalid_images"; |
scroggo | b61e206 | 2014-11-10 13:12:25 -0800 | [diff] [blame] | 31 | |
scroggo | 139491f | 2015-07-10 09:32:09 -0700 | [diff] [blame] | 32 | for (size_t i = 0; i < SK_ARRAY_COUNT(badImages); ++i) { |
bungeman | f93d711 | 2016-09-16 06:24:20 -0700 | [diff] [blame] | 33 | SkString resourcePath = SkOSPath::Join(badImagesFolder, badImages[i]); |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 34 | std::unique_ptr<SkStream> stream(GetResourceAsStream(resourcePath.c_str())); |
Mike Reed | ede7bac | 2017-07-23 15:30:02 -0400 | [diff] [blame] | 35 | std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream))); |
msarett | 7f7ec20 | 2016-03-01 12:12:27 -0800 | [diff] [blame] | 36 | |
| 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 | } |
scroggo | b61e206 | 2014-11-10 13:12:25 -0800 | [diff] [blame] | 45 | } |
| 46 | } |