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/SkCanvas.h" 9 #include "include/core/SkData.h" 10 #include "include/core/SkPicture.h" 11 #include "include/core/SkStream.h" 12 #include "include/core/SkSurface.h" 13 14 constexpr static SkISize kCanvasSize= {128, 160}; 15 FuzzSKP(sk_sp<SkData> bytes)16void FuzzSKP(sk_sp<SkData> bytes) { 17 sk_sp<SkPicture> pic = SkPicture::MakeFromData(bytes->data(), bytes->size()); 18 if (!pic) { 19 SkDebugf("[terminated] Couldn't decode as a picture.\n"); 20 return; 21 } 22 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(kCanvasSize.width(), 23 kCanvasSize.height()); 24 surface->getCanvas()->drawPicture(pic); 25 pic->approximateBytesUsed(); 26 pic->approximateOpCount(); 27 return; 28 } 29 30 #if defined(SK_BUILD_FOR_LIBFUZZER) LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)31extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 32 auto bytes = SkData::MakeWithoutCopy(data, size); 33 FuzzSKP(bytes); 34 return 0; 35 } 36 #endif 37