Coverage Report

Created: 2025-09-04 06:36

/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
6
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
12
6
  int32_t i = 0, dsize = 0;
13
6
  int32_t nchunk = 0;
14
15
6
  blosc2_init();
16
6
  blosc2_set_nthreads(1);
17
18
  /* Create a super-chunk backed by an in-memory frame */
19
6
  blosc2_schunk* schunk = blosc2_schunk_from_buffer((uint8_t *) data, (int64_t)size, false);
20
6
  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
0
  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
0
  uint8_t *uncompressed_data = (uint8_t *)malloc((size_t)schunk->nbytes+1);
32
0
  if (uncompressed_data != NULL) {
33
0
    for (i = 0, nchunk = 0; nchunk < schunk->nchunks-1; nchunk++) {
34
0
      dsize = blosc2_schunk_decompress_chunk(schunk, nchunk, uncompressed_data + i, schunk->chunksize);
35
0
      if (dsize < 0) {
36
0
        printf("Decompression error.  Error code: %d\n", dsize);
37
0
        break;
38
0
      }
39
0
      i += dsize;
40
0
    }
41
42
0
    free(uncompressed_data);
43
0
  }
44
45
0
  blosc2_schunk_free(schunk);
46
0
  blosc2_destroy();
47
0
  return 0;
48
0
}
49
50
#ifdef __cplusplus
51
}
52
#endif