FuzzTextBlobDeserialize.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright 2018 Google, LLC
  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/core/SkCanvas.h"
  8. #include "include/core/SkPaint.h"
  9. #include "include/core/SkSurface.h"
  10. #include "src/core/SkFontMgrPriv.h"
  11. #include "src/core/SkReadBuffer.h"
  12. #include "src/core/SkTextBlobPriv.h"
  13. #include "tools/fonts/TestFontMgr.h"
  14. void FuzzTextBlobDeserialize(SkReadBuffer& buf) {
  15. auto tb = SkTextBlobPriv::MakeFromBuffer(buf);
  16. if (!buf.isValid()) {
  17. return;
  18. }
  19. auto s = SkSurface::MakeRasterN32Premul(128, 128);
  20. if (!s) {
  21. // May return nullptr in memory-constrained fuzzing environments
  22. return;
  23. }
  24. s->getCanvas()->drawTextBlob(tb, 200, 200, SkPaint());
  25. }
  26. #if defined(IS_FUZZING_WITH_LIBFUZZER)
  27. extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  28. gSkFontMgr_DefaultFactory = &ToolUtils::MakePortableFontMgr;
  29. SkReadBuffer buf(data, size);
  30. FuzzTextBlobDeserialize(buf);
  31. return 0;
  32. }
  33. #endif