Merge changes I8ae09473,I678c8b1e

* changes:
  fuzz_utils.h: rename max() to Max()
  fuzz_utils.h: make functions WEBP_INLINE
This commit is contained in:
James Zern 2020-10-19 21:56:35 +00:00 committed by Gerrit Code Review
commit eb44119c3d
2 changed files with 28 additions and 22 deletions

View File

@ -35,7 +35,7 @@ static const size_t kFuzzPxLimit = 1024 * 1024;
static const int kFuzzFrameLimit = 3;
// Reads and sums (up to) 128 spread-out bytes.
static uint8_t FuzzHash(const uint8_t* const data, size_t size) {
static WEBP_INLINE uint8_t FuzzHash(const uint8_t* const data, size_t size) {
uint8_t value = 0;
size_t incr = size / 128;
if (!incr) incr = 1;
@ -46,8 +46,9 @@ static uint8_t FuzzHash(const uint8_t* const data, size_t size) {
//------------------------------------------------------------------------------
// Extract an integer in [0, max_value].
static uint32_t Extract(uint32_t max_value, const uint8_t data[], size_t size,
uint32_t* const bit_pos) {
static WEBP_INLINE uint32_t Extract(uint32_t max_value,
const uint8_t data[], size_t size,
uint32_t* const bit_pos) {
uint32_t v = 0;
uint32_t range = 1;
while (*bit_pos < 8 * size && range <= max_value) {
@ -64,28 +65,31 @@ static uint32_t Extract(uint32_t max_value, const uint8_t data[], size_t size,
static VP8CPUInfo GetCPUInfo;
static int GetCPUInfoNoSSE41(CPUFeature feature) {
static WEBP_INLINE int GetCPUInfoNoSSE41(CPUFeature feature) {
if (feature == kSSE4_1 || feature == kAVX) return 0;
return GetCPUInfo(feature);
}
static int GetCPUInfoNoAVX(CPUFeature feature) {
static WEBP_INLINE int GetCPUInfoNoAVX(CPUFeature feature) {
if (feature == kAVX) return 0;
return GetCPUInfo(feature);
}
static int GetCPUInfoForceSlowSSSE3(CPUFeature feature) {
static WEBP_INLINE int GetCPUInfoForceSlowSSSE3(CPUFeature feature) {
if (feature == kSlowSSSE3 && GetCPUInfo(kSSE3)) {
return 1; // we have SSE3 -> force SlowSSSE3
}
return GetCPUInfo(feature);
}
static int GetCPUInfoOnlyC(CPUFeature feature) { return 0; }
static WEBP_INLINE int GetCPUInfoOnlyC(CPUFeature feature) {
(void)feature;
return 0;
}
static void ExtractAndDisableOptimizations(VP8CPUInfo default_VP8GetCPUInfo,
const uint8_t data[], size_t size,
uint32_t* const bit_pos) {
static WEBP_INLINE void ExtractAndDisableOptimizations(
VP8CPUInfo default_VP8GetCPUInfo, const uint8_t data[], size_t size,
uint32_t* const bit_pos) {
GetCPUInfo = default_VP8GetCPUInfo;
const VP8CPUInfo kVP8CPUInfos[5] = {GetCPUInfoOnlyC, GetCPUInfoForceSlowSSSE3,
GetCPUInfoNoSSE41, GetCPUInfoNoAVX,
@ -96,8 +100,9 @@ static void ExtractAndDisableOptimizations(VP8CPUInfo default_VP8GetCPUInfo,
//------------------------------------------------------------------------------
static int ExtractWebPConfig(WebPConfig* const config, const uint8_t data[],
size_t size, uint32_t* const bit_pos) {
static WEBP_INLINE int ExtractWebPConfig(WebPConfig* const config,
const uint8_t data[], size_t size,
uint32_t* const bit_pos) {
if (config == NULL || !WebPConfigInit(config)) return 0;
config->lossless = Extract(1, data, size, bit_pos);
config->quality = Extract(100, data, size, bit_pos);
@ -130,9 +135,9 @@ static int ExtractWebPConfig(WebPConfig* const config, const uint8_t data[],
//------------------------------------------------------------------------------
static int ExtractSourcePicture(WebPPicture* const pic,
const uint8_t data[], size_t size,
uint32_t* const bit_pos) {
static WEBP_INLINE int ExtractSourcePicture(WebPPicture* const pic,
const uint8_t data[], size_t size,
uint32_t* const bit_pos) {
if (pic == NULL) return 0;
// Pick a source picture.
@ -164,10 +169,11 @@ static int ExtractSourcePicture(WebPPicture* const pic,
//------------------------------------------------------------------------------
static int max(int a, int b) { return ((a < b) ? b : a); }
static WEBP_INLINE int Max(int a, int b) { return ((a < b) ? b : a); }
static int ExtractAndCropOrScale(WebPPicture* const pic, const uint8_t data[],
size_t size, uint32_t* const bit_pos) {
static WEBP_INLINE int ExtractAndCropOrScale(WebPPicture* const pic,
const uint8_t data[], size_t size,
uint32_t* const bit_pos) {
if (pic == NULL) return 0;
#if !defined(WEBP_REDUCE_SIZE)
const int alter_input = Extract(1, data, size, bit_pos);
@ -178,8 +184,8 @@ static int ExtractAndCropOrScale(WebPPicture* const pic, const uint8_t data[],
if (crop_or_scale) {
const uint32_t left_ratio = 1 + Extract(7, data, size, bit_pos);
const uint32_t top_ratio = 1 + Extract(7, data, size, bit_pos);
const int cropped_width = max(1, pic->width / width_ratio);
const int cropped_height = max(1, pic->height / height_ratio);
const int cropped_width = Max(1, pic->width / width_ratio);
const int cropped_height = Max(1, pic->height / height_ratio);
const int cropped_left = (pic->width - cropped_width) / left_ratio;
const int cropped_top = (pic->height - cropped_height) / top_ratio;
return WebPPictureCrop(pic, cropped_left, cropped_top, cropped_width,

View File

@ -4,7 +4,7 @@
CC = clang
CXX = clang++
CFLAGS = -fsanitize=fuzzer -I../../src -I../..
CFLAGS = -fsanitize=fuzzer -I../../src -I../.. -Wall -Wextra
CXXFLAGS = $(CFLAGS)
LDFLAGS = -fsanitize=fuzzer
LDLIBS = ../../src/mux/libwebpmux.a ../../src/demux/libwebpdemux.a
@ -14,7 +14,7 @@ FUZZERS = advanced_api_fuzzer animation_api_fuzzer animencoder_fuzzer
FUZZERS += animdecoder_fuzzer mux_demux_api_fuzzer enc_dec_fuzzer
FUZZERS += simple_api_fuzzer
%.o: %.c %.cc fuzz_utils.h img_alpha.h img_grid.h img_peak.h
%.o: fuzz_utils.h img_alpha.h img_grid.h img_peak.h
all: $(FUZZERS)
define FUZZER_template