Coverage Report

Created: 2026-12-01 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zlib-ng/test/fuzz/fuzzer_checksum.c
Line
Count
Source
1
#include "zbuild.h"
2
#include <assert.h>
3
#ifdef ZLIB_COMPAT
4
#  include "zlib.h"
5
#else
6
#  include "zlib-ng.h"
7
#endif
8
9
614
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen) {
10
614
    uint32_t crc0 = PREFIX(crc32_z)(0L, NULL, 0);
11
614
    uint32_t crc1 = crc0;
12
614
    uint32_t crc2 = crc0;
13
614
    uint32_t adler0 = PREFIX(adler32_z)(0L, NULL, 0);
14
614
    uint32_t adler1 = adler0;
15
614
    uint32_t adler2 = adler0;
16
614
    uint32_t combine1, combine2;
17
    /* Checksum with a buffer of size equal to the first byte in the input. */
18
614
    uint32_t buffSize = data[0];
19
614
    uint32_t offset = 0;
20
614
    uint32_t op;
21
22
    /* Discard inputs larger than 1Mb. */
23
614
    static size_t kMaxSize = 1024 * 1024;
24
614
    if (dataLen < 1 || dataLen > kMaxSize)
25
0
        return 0;
26
27
    /* Make sure the buffer has at least a byte. */
28
614
    if (buffSize == 0)
29
43
        ++buffSize;
30
31
    /* CRC32 */
32
614
    op = PREFIX(crc32_combine_gen)(buffSize);
33
1.92M
    for (offset = 0; offset + buffSize <= dataLen; offset += buffSize) {
34
1.92M
        uint32_t crc3 = PREFIX(crc32_z)(crc0, data + offset, buffSize);
35
1.92M
        uint32_t crc4 = PREFIX(crc32_combine_op)(crc1, crc3, op);
36
1.92M
        crc1 = PREFIX(crc32_z)(crc1, data + offset, buffSize);
37
1.92M
        assert(crc1 == crc4);
38
1.92M
        Z_UNUSED(crc1);
39
1.92M
        Z_UNUSED(crc4);
40
1.92M
    }
41
614
    crc1 = PREFIX(crc32_z)(crc1, data + offset, dataLen % buffSize);
42
43
614
    crc2 = PREFIX(crc32_z)(crc2, data, dataLen);
44
45
614
    assert(crc1 == crc2);
46
614
    Z_UNUSED(crc1);
47
614
    Z_UNUSED(crc2);
48
614
    combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen);
49
614
    combine2 = PREFIX(crc32_combine)(crc1, crc1, (z_off_t)dataLen);
50
614
    assert(combine1 == combine2);
51
52
    /* Fast CRC32 combine. */
53
614
    op = PREFIX(crc32_combine_gen)((z_off_t)dataLen);
54
614
    combine1 = PREFIX(crc32_combine_op)(crc1, crc2, op);
55
614
    combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op);
56
614
    assert(combine1 == combine2);
57
614
    combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen);
58
614
    combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op);
59
614
    assert(combine1 == combine2);
60
61
    /* Adler32 */
62
1.92M
    for (offset = 0; offset + buffSize <= dataLen; offset += buffSize)
63
1.92M
        adler1 = PREFIX(adler32_z)(adler1, data + offset, buffSize);
64
614
    adler1 = PREFIX(adler32_z)(adler1, data + offset, dataLen % buffSize);
65
66
614
    adler2 = PREFIX(adler32_z)(adler2, data, dataLen);
67
68
614
    assert(adler1 == adler2);
69
614
    Z_UNUSED(adler1);
70
614
    Z_UNUSED(adler2);
71
614
    combine1 = PREFIX(adler32_combine)(adler1, adler2, (z_off_t)dataLen);
72
614
    combine2 = PREFIX(adler32_combine)(adler1, adler1, (z_off_t)dataLen);
73
614
    assert(combine1 == combine2);
74
614
    Z_UNUSED(combine1);
75
614
    Z_UNUSED(combine2);
76
77
    /* This function must return 0. */
78
614
    return 0;
79
614
}