skia2/fuzz/Fuzz.cpp
Kevin Lubick bc9a1a837d Make fuzz::next overloads more consistent
Some oss-fuzz bugs (like the linked one) would not reproduce
in Skia proper due to the fact that there were subtle overloads
of the various Fuzz::next() methods in FuzzCanvas.cpp that
were pulled in in Skia proper, but not oss-fuzz.

This puts all of them in to FuzzCommon.h and makes the
matrix and rrect ones opt-in (fuzz_matrix, fuzz_rrect).

Additionally, this renames fuzz.cpp -> FuzzMain.cpp so we
can properly include Fuzz.cpp in oss-fuzz without
having two mains.

Bug: oss-fuzz:10378
Change-Id: I6cf9afb471781b9fadb689482109a1e5662358b5
Reviewed-on: https://skia-review.googlesource.com/154900
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
2018-09-17 19:20:51 +00:00

40 lines
900 B
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Fuzz.h"
#include "FuzzCommon.h"
// UBSAN reminds us that bool can only legally hold 0 or 1.
void Fuzz::next(bool* b) {
uint8_t n;
this->next(&n);
*b = (n & 1) == 1;
}
void Fuzz::next(SkImageFilter::CropRect* cropRect) {
SkRect rect;
uint8_t flags;
this->next(&rect);
this->nextRange(&flags, 0, 0xF);
*cropRect = SkImageFilter::CropRect(rect, flags);
}
void Fuzz::next(SkRegion* region) {
// See FuzzCommon.h
FuzzNiceRegion(this, region, 10);
}
void Fuzz::nextRange(float* f, float min, float max) {
this->next(f);
if (!std::isnormal(*f) && *f != 0.0f) {
// Don't deal with infinity or other strange floats.
*f = max;
}
*f = min + std::fmod(std::abs(*f), (max - min + 1));
}