Coverage Report

Created: 2026-06-15 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/libfreerdp/codec/test/TestFuzzNSCodec.c
Line
Count
Source
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * libFuzzer harness for the NSCodec decoder
4
 */
5
6
#include <stddef.h>
7
#include <stdint.h>
8
9
#include <winpr/crt.h>
10
#include <winpr/wlog.h>
11
12
#include <freerdp/codec/color.h>
13
#include <freerdp/codec/nsc.h>
14
15
static int fuzz_nsc_message(UINT16 bpp, UINT32 width, UINT32 height, UINT32 dstFormat,
16
                            const uint8_t* data, size_t size)
17
1.80k
{
18
1.80k
  BYTE* dst = nullptr;
19
20
1.80k
  if (size > UINT32_MAX)
21
0
    return 0;
22
23
1.80k
  NSC_CONTEXT* ctx = nsc_context_new();
24
1.80k
  if (!ctx)
25
0
    return 0;
26
27
1.80k
  SSIZE_T stride = (SSIZE_T)width * FreeRDPGetBytesPerPixel(dstFormat);
28
1.80k
  if (stride <= 0)
29
0
    goto fail;
30
31
1.80k
  dst = calloc((size_t)height, (size_t)stride);
32
1.80k
  if (!dst)
33
0
    goto fail;
34
35
1.80k
  (void)nsc_process_message(ctx, bpp, width, height, data, (UINT32)size, dst, dstFormat,
36
1.80k
                            (UINT32)stride, 0, 0, width, height, FREERDP_FLIP_NONE);
37
38
1.80k
fail:
39
1.80k
  free(dst);
40
1.80k
  nsc_context_free(ctx);
41
1.80k
  return 0;
42
1.80k
}
43
44
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
45
612
{
46
612
  static BOOL loggingInitialized = FALSE;
47
48
612
  if (!loggingInitialized)
49
1
  {
50
1
    (void)WLog_SetLogLevel(WLog_GetRoot(), WLOG_TRACE);
51
1
    loggingInitialized = TRUE;
52
1
  }
53
54
612
  if (size < 20)
55
9
    return 0;
56
57
603
  (void)fuzz_nsc_message(32, 64, 64, PIXEL_FORMAT_BGRA32, data, size);
58
603
  (void)fuzz_nsc_message(24, 32, 32, PIXEL_FORMAT_RGBX32, data, size);
59
603
  (void)fuzz_nsc_message(16, 17, 13, PIXEL_FORMAT_RGB16, data, size);
60
603
  return 0;
61
612
}