skia2/fuzz/oss_fuzz/FuzzPathDeserialize.cpp
Kevin Lubick 37c0f7183e Add guidance for oss-fuzzer for new path version
This only changes it for the oss-fuzz executable
which allows our normal fuzz executable to repro
on older versions, if needed.

This CL also accompanies additions to the corpus
of a bunch of v4 paths.

Bug: skia:

Change-Id: I4a1a3b27f48423f2bddc73e1b8bf63b82dfa59ff
Reviewed-on: https://skia-review.googlesource.com/109560
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
2018-02-23 13:35:37 +00:00

47 lines
1.1 KiB
C++

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkReadBuffer.h"
#include "SkSurface.h"
void FuzzPathDeserialize(SkReadBuffer& buf) {
SkPath path;
buf.readPath(&path);
if (!buf.isValid()) {
return;
}
auto s = SkSurface::MakeRasterN32Premul(128, 128);
if (!s) {
// May return nullptr in memory-constrained fuzzing environments
return;
}
s->getCanvas()->drawPath(path, SkPaint());
}
#if defined(IS_FUZZING_WITH_LIBFUZZER)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size < 4) {
return 0;
}
uint32_t packed;
memcpy(&packed, data, 4);
unsigned version = packed & 0xFF;
if (version != 4) {
// Chrome only will produce version 4, so guide the fuzzer to
// only focus on those branches.
return 0;
}
SkReadBuffer buf(data, size);
FuzzPathDeserialize(buf);
return 0;
}
#endif