Coverage Report

Created: 2026-10-15 06:26

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.43k
{
20
1.43k
  if ((Size < 1) || (Size > (1u << 24)))
21
0
    return 0;
22
23
1.43k
  wImage* img = winpr_image_new();
24
1.43k
  if (!img)
25
0
    return 0;
26
27
1.43k
  const int rc = winpr_image_read_buffer(img, Data, Size);
28
1.43k
  if (rc > 0)
29
249
  {
30
249
    const UINT32 formats[] = {
31
249
      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
249
    };
42
498
    for (size_t i = 0; i < ARRAYSIZE(formats); i++)
43
249
    {
44
249
      size_t osize = 0;
45
249
      void* out = winpr_image_write_buffer(img, formats[i], &osize);
46
249
      free(out);
47
249
    }
48
249
  }
49
50
1.43k
  winpr_image_free(img, TRUE);
51
1.43k
  return 0;
52
1.43k
}