blob: 6cd0ca9dba42be00af18ee79cdba549aa235db9b [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
8#include "SkCanvas.h"
Kevin Lubickec1c6202018-12-14 11:42:53 -05009#include "SkFontMgrPriv.h"
Kevin Lubickf034d112018-02-08 14:31:24 -050010#include "SkPaint.h"
11#include "SkReadBuffer.h"
12#include "SkSurface.h"
Cary Clark53c87692018-07-17 08:59:34 -040013#include "SkTextBlobPriv.h"
Mike Klein0cffcbf92019-03-20 11:08:46 -050014#include "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