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