OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Resources.h" | 8 #include "Resources.h" |
9 #include "Test.h" | 9 #include "Test.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkCodec.h" | 11 #include "SkCodec.h" |
12 #include "SkStream.h" | 12 #include "SkStream.h" |
13 #include "SkOSFile.h" | 13 #include "SkOSFile.h" |
14 | 14 |
15 DEF_TEST(BadImage, reporter) { | 15 DEF_TEST(BadImage, reporter) { |
16 const char* const badImages [] = { | 16 const char* const badImages [] = { |
17 "sigabort_favicon.ico", | 17 "sigabort_favicon.ico", |
18 "sigsegv_favicon.ico", | 18 "sigsegv_favicon.ico", |
19 "sigsegv_favicon_2.ico", | 19 "sigsegv_favicon_2.ico", |
20 "ico_leak01.ico", | 20 "ico_leak01.ico", |
21 "ico_fuzz0.ico", | 21 "ico_fuzz0.ico", |
22 "ico_fuzz1.ico", | 22 "ico_fuzz1.ico", |
23 "skbug3442.webp", | 23 "skbug3442.webp", |
24 "skbug3429.webp", | 24 "skbug3429.webp", |
25 }; | 25 }; |
26 | 26 |
27 const char* badImagesFolder = "invalid_images"; | 27 const char* badImagesFolder = "invalid_images"; |
28 | 28 |
29 SkString resourcePath = GetResourcePath(badImagesFolder); | |
30 | |
31 for (size_t i = 0; i < SK_ARRAY_COUNT(badImages); ++i) { | 29 for (size_t i = 0; i < SK_ARRAY_COUNT(badImages); ++i) { |
32 SkString fullPath = SkOSPath::Join(resourcePath.c_str(), badImages[i]); | 30 SkString resourcePath = SkOSPath::Join(badImagesFolder, badImages[i]); |
33 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fullPath.c_str())); | 31 SkAutoTDelete<SkStream> stream(GetResourceAsStream(resourcePath.c_str())
); |
34 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); | 32 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
35 | 33 |
36 // These images are corrupt. It's not important whether we succeed/fail
in codec | 34 // These images are corrupt. It's not important whether we succeed/fail
in codec |
37 // creation or decoding. We just want to make sure that we don't crash. | 35 // creation or decoding. We just want to make sure that we don't crash. |
38 if (codec) { | 36 if (codec) { |
39 SkBitmap bm; | 37 SkBitmap bm; |
40 bm.allocPixels(codec->getInfo()); | 38 bm.allocPixels(codec->getInfo()); |
41 codec->getPixels(codec->getInfo(), bm.getPixels(), | 39 codec->getPixels(codec->getInfo(), bm.getPixels(), |
42 bm.rowBytes()); | 40 bm.rowBytes()); |
43 } | 41 } |
44 } | 42 } |
45 } | 43 } |
OLD | NEW |