2014-11-10 21:12:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Resources.h"
|
|
|
|
#include "SkBitmap.h"
|
2016-03-01 20:12:27 +00:00
|
|
|
#include "SkCodec.h"
|
2016-11-07 23:05:29 +00:00
|
|
|
#include "SkOSPath.h"
|
|
|
|
#include "SkStream.h"
|
2018-03-09 19:41:36 +00:00
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkTypes.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2014-11-10 21:12:25 +00:00
|
|
|
|
2015-07-10 16:32:09 +00:00
|
|
|
DEF_TEST(BadImage, reporter) {
|
|
|
|
const char* const badImages [] = {
|
2014-11-10 21:12:25 +00:00
|
|
|
"sigabort_favicon.ico",
|
|
|
|
"sigsegv_favicon.ico",
|
|
|
|
"sigsegv_favicon_2.ico",
|
2015-03-13 15:07:01 +00:00
|
|
|
"ico_leak01.ico",
|
|
|
|
"ico_fuzz0.ico",
|
2015-07-10 16:32:09 +00:00
|
|
|
"ico_fuzz1.ico",
|
|
|
|
"skbug3442.webp",
|
|
|
|
"skbug3429.webp",
|
2017-06-05 18:06:57 +00:00
|
|
|
"b38116746.ico",
|
2014-11-10 21:12:25 +00:00
|
|
|
};
|
|
|
|
|
2015-07-10 16:32:09 +00:00
|
|
|
const char* badImagesFolder = "invalid_images";
|
2014-11-10 21:12:25 +00:00
|
|
|
|
2015-07-10 16:32:09 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(badImages); ++i) {
|
2016-09-16 13:24:20 +00:00
|
|
|
SkString resourcePath = SkOSPath::Join(badImagesFolder, badImages[i]);
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream(resourcePath.c_str()));
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
|
2016-03-01 20:12:27 +00:00
|
|
|
|
|
|
|
// These images are corrupt. It's not important whether we succeed/fail in codec
|
|
|
|
// creation or decoding. We just want to make sure that we don't crash.
|
|
|
|
if (codec) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(codec->getInfo());
|
|
|
|
codec->getPixels(codec->getInfo(), bm.getPixels(),
|
|
|
|
bm.rowBytes());
|
|
|
|
}
|
2014-11-10 21:12:25 +00:00
|
|
|
}
|
|
|
|
}
|