skia2/fuzz/oss_fuzz/FuzzSVG.cpp
Zepeng Hu f1eb43e880 replace max_len with if statements
Change-Id: I60d60e9b9ea0b7b6544a36bef7f4e263bb9de532
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/296416
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Zepeng Hu <zepenghu@google.com>
2020-06-16 17:26:30 +00:00

44 lines
996 B
C++

/*
* Copyright 2020 Google, LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "experimental/svg/model/SkSVGDOM.h"
#include "include/core/SkData.h"
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
void FuzzSVG(sk_sp<SkData> bytes) {
uint8_t w = 100;
uint8_t h = 200;
SkMemoryStream stream(bytes);
sk_sp<SkSVGDOM> dom = SkSVGDOM::MakeFromStream(stream);
if (!dom) {
return;
}
auto s = SkSurface::MakeRasterN32Premul(128, 128);
if (!s) {
return;
}
SkSize winSize = SkSize::Make(w, h);
dom->setContainerSize(winSize);
dom->containerSize();
dom->render(s->getCanvas());
}
#if defined(IS_FUZZING_WITH_LIBFUZZER)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size > 30000) {
return 0;
}
auto bytes = SkData::MakeWithoutCopy(data, size);
FuzzSVG(bytes);
return 0;
}
#endif