Coverage Report

Created: 2025-07-18 06:49

/src/c-blosc2/tests/fuzz/fuzz_decompress_frame.c
Line
Count
Source (jump to first uncovered line)
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
15
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
12
15
  int32_t i = 0, dsize = 0;
13
15
  int32_t nchunk = 0;
14
15
15
  blosc2_init();
16
15
  blosc2_set_nthreads(1);
17
18
  /* Create a super-chunk backed by an in-memory frame */
19
15
  blosc2_schunk* schunk = blosc2_schunk_from_buffer((uint8_t *) data, (int64_t)size, false);
20
15
  if (schunk == NULL) {
21
6
    blosc2_destroy();
22
6
    return 0;
23
6
  }
24
  /* Don't allow address sanitizer to allocate more than INT32_MAX */
25
9
  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
9
  uint8_t *uncompressed_data = (uint8_t *)malloc((size_t)schunk->nbytes+1);
32
9
  if (uncompressed_data != NULL) {
33
54
    for (i = 0, nchunk = 0; nchunk < schunk->nchunks-1; nchunk++) {
34
52
      dsize = blosc2_schunk_decompress_chunk(schunk, nchunk, uncompressed_data + i, schunk->chunksize);
35
52
      if (dsize < 0) {
36
7
        printf("Decompression error.  Error code: %d\n", dsize);
37
7
        break;
38
7
      }
39
45
      i += dsize;
40
45
    }
41
42
9
    free(uncompressed_data);
43
9
  }
44
45
9
  blosc2_schunk_free(schunk);
46
9
  blosc2_destroy();
47
9
  return 0;
48
9
}
49
50
#ifdef __cplusplus
51
}
52
#endif