blob: 975eeb8b01d1f4822e62f523a1b478541753fdb8 [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
30#if defined(IS_FUZZING_WITH_LIBFUZZER)
31extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Mike Kleinea3f0142019-03-20 11:12:10 -050032 gSkFontMgr_DefaultFactory = &ToolUtils::MakePortableFontMgr;
Kevin Lubickf034d112018-02-08 14:31:24 -050033 SkReadBuffer buf(data, size);
34 FuzzTextBlobDeserialize(buf);
35 return 0;
36}
37#endif