blob: de68bcc5ff5dd73308f409aa2578674ed028be35 [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"
9#include "SkPaint.h"
10#include "SkReadBuffer.h"
11#include "SkSurface.h"
Cary Clark53c87692018-07-17 08:59:34 -040012#include "SkTextBlobPriv.h"
Kevin Lubickf034d112018-02-08 14:31:24 -050013
14void FuzzTextBlobDeserialize(SkReadBuffer& buf) {
Cary Clark53c87692018-07-17 08:59:34 -040015 auto tb = SkTextBlobPriv::MakeFromBuffer(buf);
Kevin Lubickf034d112018-02-08 14:31:24 -050016 if (!buf.isValid()) {
17 return;
18 }
19
20 auto s = SkSurface::MakeRasterN32Premul(128, 128);
21 if (!s) {
22 // May return nullptr in memory-constrained fuzzing environments
23 return;
24 }
25 s->getCanvas()->drawTextBlob(tb, 200, 200, SkPaint());
26}
27
28#if defined(IS_FUZZING_WITH_LIBFUZZER)
29extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
30 SkReadBuffer buf(data, size);
31 FuzzTextBlobDeserialize(buf);
32 return 0;
33}
34#endif