FreeRDP
Loading...
Searching...
No Matches
TestFuzzImage.c
1/*
2 * libFuzzer harness for WinPR's image parser/writer (winpr_image).
3 *
4 * This is the path that consumes untrusted image data from a remote peer:
5 * clipboard formats (image/png, image/jpeg, image/bmp, CF_DIB) are read via
6 * winpr_image_read_buffer() and re-encoded via winpr_image_write_buffer()
7 * (see winpr/libwinpr/clipboard/synthetic.c). GHSA-f3vg (PNG->CF_DIB OOB read)
8 * lived on exactly this chain; the upstream tree has no dedicated image fuzzer.
9 *
10 * Input: raw image bytes (BMP/PNG/JPEG/WebP - format sniffed by the reader).
11 */
12#include <winpr/crt.h>
13#include <winpr/image.h>
14
15#include <stdlib.h>
16#include <string.h>
17
18int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
19{
20 if ((Size < 1) || (Size > (1u << 24)))
21 return 0;
22
23 wImage* img = winpr_image_new();
24 if (!img)
25 return 0;
26
27 const int rc = winpr_image_read_buffer(img, Data, Size);
28 if (rc > 0)
29 {
30 const UINT32 formats[] = {
31 WINPR_IMAGE_BITMAP,
32#if defined(WINPR_UTILS_IMAGE_PNG)
33 WINPR_IMAGE_PNG,
34#endif
35#if defined(WINPR_UTILS_IMAGE_JPEG)
36 WINPR_IMAGE_JPEG,
37#endif
38#if defined(WINPR_UTILS_IMAGE_WEBP)
39 WINPR_IMAGE_WEBP,
40#endif
41 };
42 for (size_t i = 0; i < ARRAYSIZE(formats); i++)
43 {
44 size_t osize = 0;
45 void* out = winpr_image_write_buffer(img, formats[i], &osize);
46 free(out);
47 }
48 }
49
50 winpr_image_free(img, TRUE);
51 return 0;
52}