FreeRDP
Loading...
Searching...
No Matches
TestFuzzNSCodec.c
1
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
15static int fuzz_nsc_message(UINT16 bpp, UINT32 width, UINT32 height, UINT32 dstFormat,
16 const uint8_t* data, size_t size)
17{
18 BYTE* dst = nullptr;
19
20 if (size > UINT32_MAX)
21 return 0;
22
23 NSC_CONTEXT* ctx = nsc_context_new();
24 if (!ctx)
25 return 0;
26
27 SSIZE_T stride = (SSIZE_T)width * FreeRDPGetBytesPerPixel(dstFormat);
28 if (stride <= 0)
29 goto fail;
30
31 dst = calloc((size_t)height, (size_t)stride);
32 if (!dst)
33 goto fail;
34
35 (void)nsc_process_message(ctx, bpp, width, height, data, (UINT32)size, dst, dstFormat,
36 (UINT32)stride, 0, 0, width, height, FREERDP_FLIP_NONE);
37
38fail:
39 free(dst);
40 nsc_context_free(ctx);
41 return 0;
42}
43
44int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
45{
46 static BOOL loggingInitialized = FALSE;
47
48 if (!loggingInitialized)
49 {
50 (void)WLog_SetLogLevel(WLog_GetRoot(), WLOG_TRACE);
51 loggingInitialized = TRUE;
52 }
53
54 if (size < 20)
55 return 0;
56
57 (void)fuzz_nsc_message(32, 64, 64, PIXEL_FORMAT_BGRA32, data, size);
58 (void)fuzz_nsc_message(24, 32, 32, PIXEL_FORMAT_RGBX32, data, size);
59 (void)fuzz_nsc_message(16, 17, 13, PIXEL_FORMAT_RGB16, data, size);
60 return 0;
61}