blob: 3ace654fd8f565f960eb058f9ba6a336aff0c2a4 [file] [log] [blame]
Kevin Lubickf034d112018-02-08 14:31:24 -05001/*
Kevin Lubickdb1e5c62018-02-27 08:30:43 -05002 * Copyright 2018 Google, LLC
Kevin Lubickf034d112018-02-08 14:31:24 -05003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkCanvas.h"
9#include "include/core/SkPaint.h"
10#include "include/core/SkSurface.h"
11#include "src/core/SkFontMgrPriv.h"
12#include "src/core/SkReadBuffer.h"
13#include "src/core/SkTextBlobPriv.h"
14#include "tools/fonts/TestFontMgr.h"
Kevin Lubickf034d112018-02-08 14:31:24 -050015
16void FuzzTextBlobDeserialize(SkReadBuffer& buf) {
Cary Clark53c87692018-07-17 08:59:34 -040017 auto tb = SkTextBlobPriv::MakeFromBuffer(buf);
Kevin Lubickf034d112018-02-08 14:31:24 -050018 if (!buf.isValid()) {
19 return;
20 }
21
22 auto s = SkSurface::MakeRasterN32Premul(128, 128);
23 if (!s) {
24 // May return nullptr in memory-constrained fuzzing environments
25 return;
26 }
27 s->getCanvas()->drawTextBlob(tb, 200, 200, SkPaint());
28}
29
Kevin Lubickb45d0ca2020-09-14 13:31:25 -040030// TODO(kjlubick): remove IS_FUZZING... after https://crrev.com/c/2410304 lands
31#if defined(SK_BUILD_FOR_LIBFUZZER) || defined(IS_FUZZING_WITH_LIBFUZZER)
Kevin Lubickf034d112018-02-08 14:31:24 -050032extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Zepeng Hu5b35f212020-06-14 19:03:34 +000033 if (size > 1024) {
34 return 0;
35 }
Mike Kleinea3f0142019-03-20 11:12:10 -050036 gSkFontMgr_DefaultFactory = &ToolUtils::MakePortableFontMgr;
Kevin Lubickf034d112018-02-08 14:31:24 -050037 SkReadBuffer buf(data, size);
38 FuzzTextBlobDeserialize(buf);
39 return 0;
40}
41#endif