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