Line | Count | Source (jump to first uncovered line) |
1 | | #include <stdio.h> |
2 | | #include <stddef.h> |
3 | | #include <stdint.h> |
4 | | #include <string.h> |
5 | | #include <assert.h> |
6 | | #include <stdlib.h> |
7 | | #include <inttypes.h> |
8 | | #include "zlib.h" |
9 | | |
10 | 545 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen) { |
11 | 545 | uint32_t crc0 = crc32(0L, NULL, 0); |
12 | 545 | uint32_t crc1 = crc0; |
13 | 545 | uint32_t crc2 = crc0; |
14 | 545 | uint32_t adler0 = adler32(0L, NULL, 0); |
15 | 545 | uint32_t adler1 = adler0; |
16 | 545 | uint32_t adler2 = adler0; |
17 | | /* Checksum with a buffer of size equal to the first byte in the input. */ |
18 | 545 | uint32_t buffSize = data[0]; |
19 | 545 | uint32_t offset = 0; |
20 | 545 | uint32_t op; |
21 | | |
22 | | /* Discard inputs larger than 1Mb. */ |
23 | 545 | static size_t kMaxSize = 1024 * 1024; |
24 | 545 | if (dataLen < 1 || dataLen > kMaxSize) |
25 | 0 | return 0; |
26 | | |
27 | | /* Make sure the buffer has at least a byte. */ |
28 | 545 | if (buffSize == 0) |
29 | 87 | ++buffSize; |
30 | | |
31 | | /* CRC32 */ |
32 | 545 | op = crc32_combine_gen(buffSize); |
33 | 5.06M | for (offset = 0; offset + buffSize <= dataLen; offset += buffSize) { |
34 | 5.06M | uint32_t crc3 = crc32_z(crc0, data + offset, buffSize); |
35 | 5.06M | uint32_t crc4 = crc32_combine_op(crc1, crc3, op); |
36 | 5.06M | crc1 = crc32_z(crc1, data + offset, buffSize); |
37 | 5.06M | assert(crc1 == crc4); |
38 | 5.06M | } |
39 | 545 | crc1 = crc32_z(crc1, data + offset, dataLen % buffSize); |
40 | | |
41 | 545 | crc2 = crc32(crc2, data, (uint32_t) dataLen); |
42 | | |
43 | 545 | assert(crc1 == crc2); |
44 | 545 | assert(crc32_combine(crc1, crc2, dataLen) == |
45 | 545 | crc32_combine(crc1, crc1, dataLen)); |
46 | | |
47 | | /* Fast CRC32 combine. */ |
48 | 545 | op = crc32_combine_gen(dataLen); |
49 | 545 | assert(crc32_combine_op(crc1, crc2, op) == |
50 | 545 | crc32_combine_op(crc2, crc1, op)); |
51 | 545 | assert(crc32_combine(crc1, crc2, dataLen) == |
52 | 545 | crc32_combine_op(crc2, crc1, op)); |
53 | | |
54 | | /* Adler32 */ |
55 | 5.06M | for (offset = 0; offset + buffSize <= dataLen; offset += buffSize) |
56 | 5.06M | adler1 = adler32_z(adler1, data + offset, buffSize); |
57 | 545 | adler1 = adler32_z(adler1, data + offset, dataLen % buffSize); |
58 | | |
59 | 545 | adler2 = adler32(adler2, data, (uint32_t) dataLen); |
60 | | |
61 | 545 | assert(adler1 == adler2); |
62 | 545 | assert(adler32_combine(adler1, adler2, dataLen) == |
63 | 545 | adler32_combine(adler1, adler1, dataLen)); |
64 | | |
65 | | /* This function must return 0. */ |
66 | 545 | return 0; |
67 | 545 | } |