Line | Count | Source |
1 | | // Copyright 2018 Google Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | // |
15 | | //////////////////////////////////////////////////////////////////////////////// |
16 | | |
17 | | #include <stdint.h> |
18 | | #include <stdlib.h> |
19 | | |
20 | | // Arbitrary limits to prevent OOM, timeout, or slow execution. |
21 | | // |
22 | | // The decoded image size, and for animations additionally the canvas size. |
23 | | static const size_t kFuzzPxLimit = 1024 * 1024; |
24 | | // Demuxed or decoded animation frames. |
25 | | static const int kFuzzFrameLimit = 3; |
26 | | |
27 | | // Reads and sums (up to) 128 spread-out bytes. |
28 | 8.04k | uint8_t FuzzHash(const uint8_t* const data, size_t size) { |
29 | 8.04k | uint8_t value = 0; |
30 | 8.04k | size_t incr = size / 128; |
31 | 8.04k | if (!incr) incr = 1; |
32 | 443k | for (size_t i = 0; i < size; i += incr) value += data[i]; |
33 | 8.04k | return value; |
34 | 8.04k | } |