blob: 6b82c79358099678d9dca5b25e93b66485fb072b [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"
Kevin Lubickec1c6202018-12-14 11:42:53 -050013#include "SkTestFontMgr.h"
Cary Clark53c87692018-07-17 08:59:34 -040014#include "SkTextBlobPriv.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) {
Kevin Lubickec1c6202018-12-14 11:42:53 -050032 gSkFontMgr_DefaultFactory = &sk_tool_utils::MakePortableFontMgr;
Kevin Lubickf034d112018-02-08 14:31:24 -050033 SkReadBuffer buf(data, size);
34 FuzzTextBlobDeserialize(buf);
35 return 0;
36}
37#endif