Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
FuzzCOLRv1.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google, LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
10#include "include/core/SkFont.h"
16
17#include <algorithm>
18
19void FuzzCOLRv1(const uint8_t* data, size_t size) {
20 // We do not want the portable fontmgr here, as it does not allow creation of fonts from bytes.
22 std::unique_ptr<SkStreamAsset> stream = SkMemoryStream::MakeDirect(data, size);
23 sk_sp<SkTypeface> typeface = mgr->makeFromStream(std::move(stream), 0);
24
25 if (!typeface) {
26 return;
27 }
28
30 if (!s) {
31 return;
32 }
33
34 // Place at a baseline in the lower part of the canvas square, but canvas size and baseline
35 // placement are chosen arbitrarily and we just need to cover colrv1 rendering in this
36 // fuzz test.
37 SkFont colrv1Font = SkFont(typeface, 120);
38 SkCanvas* canvas = s->getCanvas();
40 int numGlyphs = typeface->countGlyphs();
41
42 for (int i = 0; i < std::min(numGlyphs, 10); ++i) {
43 SkPoint origin = SkPoint::Make(10, 108);
44 SkPoint position = SkPoint::Make(0, 0);
45 SkGlyphID glyphId = i;
46 canvas->drawGlyphs(1, &glyphId, &position, origin, colrv1Font, paint);
47 }
48}
49
50#if defined(SK_BUILD_FOR_LIBFUZZER)
51extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
52 // COLRv1 corpus file sizes range from 8k for a small test glyph file to about 80k covering
53 // most of the complex Noto Emoji glyphs, compare:
54 // See https://github.com/googlefonts/color-fonts/blob/main/rebuild_fuzzer_corpus.py
55 if (size > 80 * 1024) {
56 return 0;
57 }
58 FuzzCOLRv1(data, size);
59 return 0;
60}
61#endif
void FuzzCOLRv1(const uint8_t *data, size_t size)
uint16_t SkGlyphID
Definition SkTypes.h:179
void drawGlyphs(int count, const SkGlyphID glyphs[], const SkPoint positions[], const uint32_t clusters[], int textByteCount, const char utf8text[], SkPoint origin, const SkFont &font, const SkPaint &paint)
static std::unique_ptr< SkMemoryStream > MakeDirect(const void *data, size_t length)
Definition SkStream.cpp:310
const Paint & paint
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
struct MyStruct s
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
sk_sp< SkFontMgr > TestFontMgr()
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkPoint Make(float x, float y)