Coverage Report

Created: 2026-05-28 06:48

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
624
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen) {
10
624
    uint32_t crc0 = PREFIX(crc32)(0L, NULL, 0);
11
624
    uint32_t crc1 = crc0;
12
624
    uint32_t crc2 = crc0;
13
624
    uint32_t adler0 = PREFIX(adler32)(0L, NULL, 0);
14
624
    uint32_t adler1 = adler0;
15
624
    uint32_t adler2 = adler0;
16
624
    uint32_t combine1, combine2;
17
    /* Checksum with a buffer of size equal to the first byte in the input. */
18
624
    uint32_t buffSize = data[0];
19
624
    uint32_t offset = 0;
20
624
    uint32_t op;
21
22
    /* Discard inputs larger than 1Mb. */
23
624
    static size_t kMaxSize = 1024 * 1024;
24
624
    if (dataLen < 1 || dataLen > kMaxSize)
25
0
        return 0;
26
27
    /* Make sure the buffer has at least a byte. */
28
624
    if (buffSize == 0)
29
44
        ++buffSize;
30
31
    /* CRC32 */
32
624
    op = PREFIX(crc32_combine_gen)(buffSize);
33
3.51M
    for (offset = 0; offset + buffSize <= dataLen; offset += buffSize) {
34
3.51M
        uint32_t crc3 = PREFIX(crc32_z)(crc0, data + offset, buffSize);
35
3.51M
        uint32_t crc4 = PREFIX(crc32_combine_op)(crc1, crc3, op);
36
3.51M
        crc1 = PREFIX(crc32_z)(crc1, data + offset, buffSize);
37
3.51M
        assert(crc1 == crc4);
38
3.51M
        Z_UNUSED(crc1);
39
3.51M
        Z_UNUSED(crc4);
40
3.51M
    }
41
624
    crc1 = PREFIX(crc32_z)(crc1, data + offset, dataLen % buffSize);
42
43
624
    crc2 = PREFIX(crc32_z)(crc2, data, dataLen);
44
45
624
    assert(crc1 == crc2);
46
624
    Z_UNUSED(crc1);
47
624
    Z_UNUSED(crc2);
48
624
    combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen);
49
624
    combine2 = PREFIX(crc32_combine)(crc1, crc1, (z_off_t)dataLen);
50
624
    assert(combine1 == combine2);
51
52
    /* Fast CRC32 combine. */
53
624
    op = PREFIX(crc32_combine_gen)((z_off_t)dataLen);
54
624
    combine1 = PREFIX(crc32_combine_op)(crc1, crc2, op);
55
624
    combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op);
56
624
    assert(combine1 == combine2);
57
624
    combine1 = PREFIX(crc32_combine)(crc1, crc2, (z_off_t)dataLen);
58
624
    combine2 = PREFIX(crc32_combine_op)(crc2, crc1, op);
59
624
    assert(combine1 == combine2);
60
61
    /* Adler32 */
62
3.51M
    for (offset = 0; offset + buffSize <= dataLen; offset += buffSize)
63
3.51M
        adler1 = PREFIX(adler32_z)(adler1, data + offset, buffSize);
64
624
    adler1 = PREFIX(adler32_z)(adler1, data + offset, dataLen % buffSize);
65
66
624
    adler2 = PREFIX(adler32_z)(adler2, data, dataLen);
67
68
624
    assert(adler1 == adler2);
69
624
    Z_UNUSED(adler1);
70
624
    Z_UNUSED(adler2);
71
624
    combine1 = PREFIX(adler32_combine)(adler1, adler2, (z_off_t)dataLen);
72
624
    combine2 = PREFIX(adler32_combine)(adler1, adler1, (z_off_t)dataLen);
73
624
    assert(combine1 == combine2);
74
624
    Z_UNUSED(combine1);
75
624
    Z_UNUSED(combine2);
76
77
    /* This function must return 0. */
78
624
    return 0;
79
624
}