skia_path_fuzzer.cc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <stddef.h>
  5. #include <stdint.h>
  6. #include "testing/libfuzzer/fuzzers/skia_path_common.h"
  7. #include "third_party/skia/include/core/SkCanvas.h"
  8. #include "third_party/skia/include/core/SkPaint.h"
  9. #include "third_party/skia/include/core/SkPath.h"
  10. #include "third_party/skia/include/core/SkSurface.h"
  11. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  12. uint8_t w, h, anti_alias;
  13. if (!read<uint8_t>(&data, &size, &w))
  14. return 0;
  15. if (!read<uint8_t>(&data, &size, &h))
  16. return 0;
  17. if (!read<uint8_t>(&data, &size, &anti_alias))
  18. return 0;
  19. SkScalar a, b, c, d;
  20. if (!read<SkScalar>(&data, &size, &a))
  21. return 0;
  22. if (!read<SkScalar>(&data, &size, &b))
  23. return 0;
  24. if (!read<SkScalar>(&data, &size, &c))
  25. return 0;
  26. if (!read<SkScalar>(&data, &size, &d))
  27. return 0;
  28. // In this case, we specifically don't want to include kDone_Verb.
  29. SkPath path;
  30. BuildPath(&data, &size, &path, SkPath::Verb::kClose_Verb);
  31. // Try a few potentially interesting things with our path.
  32. path.contains(a, b);
  33. path.conservativelyContainsRect(SkRect::MakeLTRB(a, b, c, d));
  34. SkPaint paint_fill;
  35. paint_fill.setStyle(SkPaint::Style::kFill_Style);
  36. paint_fill.setAntiAlias(anti_alias & 1);
  37. SkPaint paint_stroke;
  38. paint_stroke.setStyle(SkPaint::Style::kStroke_Style);
  39. paint_stroke.setStrokeWidth(1);
  40. paint_stroke.setAntiAlias(anti_alias & 1);
  41. SkPath dst_path;
  42. paint_stroke.getFillPath(path, &dst_path, nullptr);
  43. // Width and height should never be 0.
  44. auto surface(SkSurface::MakeRasterN32Premul(w ? w : 1, h ? h : 1));
  45. surface->getCanvas()->drawPath(path, paint_fill);
  46. surface->getCanvas()->drawPath(path, paint_stroke);
  47. return 0;
  48. }