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/SkData.h" 9 #include "include/core/SkStream.h" 10 #include "include/core/SkSurface.h" 11 #include "modules/svg/include/SkSVGDOM.h" 12 #include "modules/svg/include/SkSVGNode.h" 13 14 #if defined(SK_ENABLE_SVG) 15 FuzzSVG(sk_sp<SkData> bytes)16void FuzzSVG(sk_sp<SkData> bytes) { 17 uint8_t w = 100; 18 uint8_t h = 200; 19 20 SkMemoryStream stream(bytes); 21 sk_sp<SkSVGDOM> dom = SkSVGDOM::MakeFromStream(stream); 22 if (!dom) { 23 return; 24 } 25 26 auto s = SkSurface::MakeRasterN32Premul(128, 128); 27 if (!s) { 28 return; 29 } 30 SkSize winSize = SkSize::Make(w, h); 31 dom->setContainerSize(winSize); 32 dom->containerSize(); 33 dom->render(s->getCanvas()); 34 35 } 36 37 #if defined(SK_BUILD_FOR_LIBFUZZER) LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)38extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 39 if (size > 30000) { 40 return 0; 41 } 42 auto bytes = SkData::MakeWithoutCopy(data, size); 43 FuzzSVG(bytes); 44 return 0; 45 } 46 #endif 47 48 #endif // SK_ENABLE_SVG 49