1 /* 2 * Copyright 2020 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 8 #include "include/core/SkStream.h" 9 #include "include/core/SkSurface.h" 10 #include "modules/skshaper/utils/FactoryHelpers.h" 11 #include "modules/svg/include/SkSVGDOM.h" 12 #include "modules/svg/include/SkSVGNode.h" 13 #include "tools/fonts/TestFontMgr.h" 14 15 #if defined(SK_ENABLE_SVG) 16 FuzzSVG(const uint8_t * data,size_t size)17void FuzzSVG(const uint8_t *data, size_t size) { 18 uint8_t w = 100; 19 uint8_t h = 200; 20 21 SkMemoryStream stream(data, size); 22 sk_sp<SkSVGDOM> dom = SkSVGDOM::Builder() 23 .setFontManager(ToolUtils::MakePortableFontMgr()) 24 .setTextShapingFactory(SkShapers::BestAvailable()) 25 .make(stream); 26 if (!dom) { 27 return; 28 } 29 30 auto s = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(128, 128)); 31 if (!s) { 32 return; 33 } 34 SkSize winSize = SkSize::Make(w, h); 35 dom->setContainerSize(winSize); 36 dom->containerSize(); 37 dom->render(s->getCanvas()); 38 } 39 40 #if defined(SK_BUILD_FOR_LIBFUZZER) LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)41extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 42 if (size > 30000) { 43 return 0; 44 } 45 FuzzSVG(data, size); 46 return 0; 47 } 48 #endif 49 50 #endif // SK_ENABLE_SVG 51