FuzzRegionSetPath.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright 2018 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 "fuzz/Fuzz.h"
  8. #include "fuzz/FuzzCommon.h"
  9. #include "include/core/SkData.h"
  10. #include "include/core/SkPath.h"
  11. #include "include/core/SkRegion.h"
  12. void FuzzRegionSetPath(Fuzz* fuzz) {
  13. SkPath p;
  14. FuzzNicePath(fuzz, &p, 1000);
  15. SkRegion r1;
  16. bool initR1;
  17. fuzz->next(&initR1);
  18. if (initR1) {
  19. fuzz->next(&r1);
  20. }
  21. SkRegion r2;
  22. fuzz->next(&r2);
  23. r1.setPath(p, r2);
  24. // Do some follow on computations to make sure region is well-formed.
  25. r1.computeRegionComplexity();
  26. r1.isComplex();
  27. if (r1 == r2) {
  28. r1.contains(0,0);
  29. } else {
  30. r1.contains(1,1);
  31. }
  32. }
  33. #if defined(IS_FUZZING_WITH_LIBFUZZER)
  34. extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  35. sk_sp<SkData> bytes(SkData::MakeWithoutCopy(data, size));
  36. Fuzz fuzz(bytes);
  37. FuzzRegionSetPath(&fuzz);
  38. return 0;
  39. }
  40. #endif