BadIcoTest.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include "include/codec/SkCodec.h"
  8. #include "include/core/SkBitmap.h"
  9. #include "include/core/SkStream.h"
  10. #include "include/core/SkString.h"
  11. #include "include/core/SkTypes.h"
  12. #include "src/utils/SkOSPath.h"
  13. #include "tests/Test.h"
  14. #include "tools/Resources.h"
  15. #include <memory>
  16. #include <utility>
  17. DEF_TEST(BadImage, reporter) {
  18. const char* const badImages [] = {
  19. "sigabort_favicon.ico",
  20. "sigsegv_favicon.ico",
  21. "sigsegv_favicon_2.ico",
  22. "ico_leak01.ico",
  23. "ico_fuzz0.ico",
  24. "ico_fuzz1.ico",
  25. "skbug3442.webp",
  26. "skbug3429.webp",
  27. "b38116746.ico",
  28. };
  29. const char* badImagesFolder = "invalid_images";
  30. for (size_t i = 0; i < SK_ARRAY_COUNT(badImages); ++i) {
  31. SkString resourcePath = SkOSPath::Join(badImagesFolder, badImages[i]);
  32. std::unique_ptr<SkStream> stream(GetResourceAsStream(resourcePath.c_str()));
  33. std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
  34. // These images are corrupt. It's not important whether we succeed/fail in codec
  35. // creation or decoding. We just want to make sure that we don't crash.
  36. if (codec) {
  37. SkBitmap bm;
  38. bm.allocPixels(codec->getInfo());
  39. codec->getPixels(codec->getInfo(), bm.getPixels(),
  40. bm.rowBytes());
  41. }
  42. }
  43. }