• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zlib-ng / zlib-ng / 21758018679

06 Feb 2026 04:33PM UTC coverage: 94.713% (-0.02%) from 94.736%
21758018679

Pull #2139

github

web-flow
Merge e366b2b5e into 98539ef92
Pull Request #2139: Add compile-time feature detection macros

8863 of 9520 branches covered (93.1%)

Branch coverage included in aggregate %.

129 of 129 new or added lines in 2 files covered. (100.0%)

19 existing lines in 8 files now uncovered.

12457 of 12990 relevant lines covered (95.9%)

260794771.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.1
/test/fuzz/fuzzer_example_small.c
1
#include <stdio.h>
2
#include <assert.h>
3

4
#include "zbuild.h"
5
#ifdef ZLIB_COMPAT
6
#  include "zlib.h"
7
#else
8
#  include "zlib-ng.h"
9
#endif
10

11
#define CHECK_ERR(err, msg) { \
12
    if (err != Z_OK) { \
13
        fprintf(stderr, "%s error: %d\n", msg, err); \
14
        exit(1); \
15
    } \
16
}
17

18
static const uint8_t *data;
19
static size_t dataLen;
20
static alloc_func zalloc = NULL;
21
static free_func zfree = NULL;
22

23
/* ===========================================================================
24
 * Test deflate() with small buffers
25
 */
26
void test_deflate(unsigned char *compr, size_t comprLen) {
4,370✔
27
    PREFIX3(stream) c_stream; /* compression stream */
1,674✔
28
    int err;
1,674✔
29
    unsigned long len = (unsigned long)dataLen;
4,370✔
30

31
    c_stream.zalloc = zalloc;
4,370✔
32
    c_stream.zfree = zfree;
4,370✔
33
    c_stream.opaque = (void *)0;
4,370✔
34

35
    err = PREFIX(deflateInit)(&c_stream, Z_DEFAULT_COMPRESSION);
4,370✔
36
    CHECK_ERR(err, "deflateInit");
4,370✔
37

38
    c_stream.next_in = (z_const unsigned char *)data;
4,370✔
39
    c_stream.next_out = compr;
4,370✔
40

41
    while (c_stream.total_in != len && c_stream.total_out < comprLen) {
93,342,487✔
42
        c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
93,338,117✔
43
        err = PREFIX(deflate)(&c_stream, Z_NO_FLUSH);
93,338,117✔
44
        CHECK_ERR(err, "deflate small 1");
111,550,943✔
45
    }
46
    /* Finish the stream, still forcing small buffers: */
47
    for (;;) {
5,604,417✔
48
        c_stream.avail_out = 1;
13,968,071✔
49
        err = PREFIX(deflate)(&c_stream, Z_FINISH);
13,968,071✔
50
        if (err == Z_STREAM_END)
13,968,071✔
51
            break;
651✔
52
        CHECK_ERR(err, "deflate small 2");
13,963,701✔
53
    }
54

55
    err = PREFIX(deflateEnd)(&c_stream);
4,370✔
56
    CHECK_ERR(err, "deflateEnd");
4,370✔
57
}
4,370✔
58

59
/* ===========================================================================
60
 * Test inflate() with small buffers
61
 */
62
void test_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
4,370✔
63
    int err;
1,674✔
64
    PREFIX3(stream) d_stream; /* decompression stream */
1,674✔
65

66
    d_stream.zalloc = zalloc;
4,370✔
67
    d_stream.zfree = zfree;
4,370✔
68
    d_stream.opaque = (void *)0;
4,370✔
69

70
    d_stream.next_in = compr;
4,370✔
71
    d_stream.avail_in = 0;
4,370✔
72
    d_stream.next_out = uncompr;
4,370✔
73

74
    err = PREFIX(inflateInit)(&d_stream);
4,370✔
75
    CHECK_ERR(err, "inflateInit");
4,370✔
76

77
    while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) {
84,147,808✔
78
        d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
84,144,554✔
79
        err = PREFIX(inflate)(&d_stream, Z_NO_FLUSH);
84,144,554✔
80
        if (err == Z_STREAM_END)
84,144,554✔
81
            break;
82
        CHECK_ERR(err, "inflate");
84,145,670✔
83
    }
84

85
    err = PREFIX(inflateEnd)(&d_stream);
4,370✔
86
    CHECK_ERR(err, "inflateEnd");
4,370✔
87

88
    if (memcmp(uncompr, data, dataLen)) {
4,370✔
89
        fprintf(stderr, "bad inflate\n");
×
UNCOV
90
        exit(1);
×
91
    }
92
}
4,370✔
93

94
int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size) {
4,371✔
95
    size_t comprLen = PREFIX(compressBound)(size);
4,371✔
96
    size_t uncomprLen = size;
1,767✔
97
    uint8_t *compr, *uncompr;
1,674✔
98

99
    /* Discard inputs larger than 1Mb. */
100
    static size_t kMaxSize = 1024 * 1024;
1,116✔
101

102
    if (size < 1 || size > kMaxSize)
4,371✔
103
        return 0;
104

105
    data = d;
4,370✔
106
    dataLen = size;
4,370✔
107
    compr = (uint8_t *)calloc(1, comprLen);
4,370✔
108
    uncompr = (uint8_t *)calloc(1, uncomprLen);
4,370✔
109

110
    test_deflate(compr, comprLen);
4,370✔
111
    test_inflate(compr, comprLen, uncompr, uncomprLen);
4,370✔
112

113
    free(compr);
4,370✔
114
    free(uncompr);
4,370✔
115

116
    /* This function must return 0. */
117
    return 0;
4,370✔
118
}
651✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc