Coverage Report

Created: 2026-10-28 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/winpr/libwinpr/utils/test/TestFuzzImage.c
Line
Count
Source
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
18
int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
19
1.42k
{
20
1.42k
  if ((Size < 1) || (Size > (1u << 24)))
21
0
    return 0;
22
23
1.42k
  wImage* img = winpr_image_new();
24
1.42k
  if (!img)
25
0
    return 0;
26
27
1.42k
  const int rc = winpr_image_read_buffer(img, Data, Size);
28
1.42k
  if (rc > 0)
29
305
  {
30
305
    const UINT32 formats[] = {
31
305
      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
305
    };
42
610
    for (size_t i = 0; i < ARRAYSIZE(formats); i++)
43
305
    {
44
305
      size_t osize = 0;
45
305
      void* out = winpr_image_write_buffer(img, formats[i], &osize);
46
305
      free(out);
47
305
    }
48
305
  }
49
50
1.42k
  winpr_image_free(img, TRUE);
51
1.42k
  return 0;
52
1.42k
}