1 /* 2 * Copyright 2018 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/SkImage.h" 11 #include "include/core/SkPaint.h" 12 #include "include/core/SkSurface.h" 13 FuzzImageDecode(sk_sp<SkData> bytes)14bool FuzzImageDecode(sk_sp<SkData> bytes) { 15 auto img = SkImage::MakeFromEncoded(bytes); 16 if (nullptr == img.get()) { 17 return false; 18 } 19 20 auto s = SkSurface::MakeRasterN32Premul(128, 128); 21 if (!s) { 22 // May return nullptr in memory-constrained fuzzing environments 23 return false; 24 } 25 26 SkPaint p; 27 s->getCanvas()->drawImage(img, 0, 0, &p); 28 return true; 29 } 30 31 #if defined(IS_FUZZING_WITH_LIBFUZZER) LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)32extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 33 auto bytes = SkData::MakeWithoutCopy(data, size); 34 FuzzImageDecode(bytes); 35 return 0; 36 } 37 #endif 38