oss-fuzz/projects/libwebp/fuzz.h

35 lines
1.2 KiB
C
Raw Normal View History

// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////
#include <stdint.h>
#include <stdlib.h>
// Arbitrary limits to prevent OOM, timeout, or slow execution.
//
// The decoded image size, and for animations additionally the canvas size.
static const size_t kFuzzPxLimit = 1024 * 1024;
// Demuxed or decoded animation frames.
static const int kFuzzFrameLimit = 3;
// Reads and sums (up to) 128 spread-out bytes.
uint8_t FuzzHash(const uint8_t* const data, size_t size) {
uint8_t value = 0;
size_t incr = size / 128;
if (!incr) incr = 1;
for (size_t i = 0; i < size; i += incr) value += data[i];
return value;
}