Coverage Report

Created: 2026-07-10 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/c-blosc2/tests/fuzz/fuzz_decompress_frame.c
Line
Count
Source
1
#include <stdint.h>
2
#include <stdlib.h>
3
#include <stdio.h>
4
5
#include <blosc2.h>
6
7
#ifdef __cplusplus
8
extern "C" {
9
#endif
10
11
7.77k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
12
7.77k
  int32_t i = 0, dsize = 0;
13
7.77k
  int32_t nchunk = 0;
14
15
7.77k
  blosc2_init();
16
7.77k
  blosc2_set_nthreads(1);
17
18
  /* Create a super-chunk backed by an in-memory frame */
19
7.77k
  blosc2_schunk* schunk = blosc2_schunk_from_buffer((uint8_t *) data, (int64_t)size, false);
20
7.77k
  if (schunk == NULL) {
21
7.65k
    blosc2_destroy();
22
7.65k
    return 0;
23
7.65k
  }
24
  /* Don't allow address sanitizer to allocate more than INT32_MAX */
25
126
  if (schunk->nbytes >= INT32_MAX) {
26
0
    blosc2_schunk_free(schunk);
27
0
    blosc2_destroy();
28
0
    return 0;
29
0
  }
30
  /* Decompress data */
31
126
  uint8_t *uncompressed_data = (uint8_t *)malloc((size_t)schunk->nbytes+1);
32
126
  if (uncompressed_data != NULL) {
33
442
    for (i = 0, nchunk = 0; nchunk < schunk->nchunks-1; nchunk++) {
34
437
      dsize = blosc2_schunk_decompress_chunk(schunk, nchunk, uncompressed_data + i, schunk->chunksize);
35
437
      if (dsize < 0) {
36
120
        printf("Decompression error.  Error code: %d\n", dsize);
37
120
        break;
38
120
      }
39
317
      i += dsize;
40
317
    }
41
42
125
    free(uncompressed_data);
43
125
  }
44
45
126
  blosc2_schunk_free(schunk);
46
126
  blosc2_destroy();
47
126
  return 0;
48
126
}
49
50
#ifdef __cplusplus
51
}
52
#endif