Malformed PNG and JPEG images abort FreeRDP WinPR clients
Key facts
- Attack vector
- —
- Privileges required
- —
- User interaction
- —
- Attack complexity
- —
- Impact type
- —
- Confidentiality · integrity · availability
- —
- Fix status
- Fixed
No CVSS vector from any source. Fix status from GitHub.
Summary
FreeRDP WinPR image readers in versions up to and including 3.32.1 mishandle malformed PNG and JPEG data. The PNG reader calls libpng without an error handler, so the process aborts, and the JPEG reader keeps libjpeg's default error exit, which calls exit. An attacker who supplies crafted image bytes, for example through clipboard data, can terminate the client process.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
### Summary Two WinPR image readers call their libraries without the error-handling context those libraries require for untrusted input, so malformed image data terminates the client process: 1. `winpr_read_png_from_buffer()` (`winpr/libwinpr/utils/image.c:1170`, libpng path `WINPR_UTILS_IMAGE_PNG`) creates the libpng structs and calls `png_read_png()` **without `setjmp(png_jmpbuf(png_ptr))`**. libpng's default error handler ends in `png_longjmp()`; with no jump target set the process **aborts (SIGABRT)** on a malformed PNG - a **12-byte** input reproduces it. The PNG *writer* in the same file does it correctly ("Set up error handling.", `image.c:1092`); the reader was missed. 2. `winpr_convert_from_jpeg()` (`image.c:857`, libjpeg path) uses `jpeg_std_error()` with libjpeg's **default `error_exit`, which calls `exit(EXIT_FAILURE)`** and never returns - the function's `goto fail` paths are dead for library errors. A **62-byte truncated JPEG** terminates the process. Both readers consume attacker-controlled bytes through `winpr_image_read_buffer()` (clipboard synthesis; see Details). ### Details **PNG reader (abort).** `winpr_read_png_from_buffer()` creates `png_ptr`/`info_ptr`, checks them, then calls `png_read_png()` with no `setjmp` error handler installed. On malformed input libpng calls `png_error()` -> `png_default_error()` -> `png_longjmp()`; with no jump target set (libpng 1.6.48) this calls `abort()`. The file's own writer path (`save_png_to_buffer`, `image.c:1092-1093`, "/* Set up error handling. */ setjmp(png_jmpbuf(png_ptr))") shows the intended pattern; the reader has no equivalent. `image.c` at tag 3.32.1 contains exactly one `setjmp(png_jmpbuf(...))` - the writer's. **JPEG reader (exit).** `winpr_convert_from_jpeg()` assigns `jpeg_std_error(&jerr)` but never overrides `error_exit`; libjpeg's default `error_exit` calls `exit(EXIT_FAILURE)` directly, bypassing every error path in the function (the `goto fail` statements can only be reached via return codes, not library errors). A truncated file therefore kills the process instead of returning -1. **Same class in the JPEG writer.** The patch below also covers `winpr_convert_to_jpeg()` (`image.c:784`): it has a comment "Set up the error handler" but only installs `jpeg_std_error`; a compress error calls `exit()`. (Additionally its `fail:` label calls `jpeg_finish_compress()` after an error, which would loop forever once a handler is installed; the patch rewrites that path.) The harness below reached this site by re-encoding inputs. **Affected/verified versions.** Present in master @ `87baff6c` and in **3.32.1 (latest release; verified by comparing `image.c` at the tag)**. Not a recent regression; no patched version yet. Affects builds with `WINPR_UTILS_IMAGE_PNG` / `WINPR_UTILS_IMAGE_JPEG` - **the official packaging enables them**: `packaging/deb/freerdp-nightly/cmake-preload.cmake:28-30` (PNG+WEBP+JPEG ON), `packaging/flatpak/com.freerdp.FreeRDP.json:76` (PNG ON). `WITH_LODEPNG` builds are not affected by the PNG case (lodepng returns error codes). **Reachability.** `winpr/libwinpr/clipboard/synthetic.c` (`clipboard_synthesize_image_dib_to_format()` / `clipboard_synthesize_cf_dib()` / `clipboard_synthesize_image_bmp()`) calls `winpr_image_read_buffer()` on data supplied by the RDP peer; an RDP server (or MITM) that offers a malformed image-format clipboard payload triggers the conversion on the client when the format is used. **Relationship to recent advisories.** Distinct from GHSA-f3vg / VU#153899 / VU#153900 (same clipboard-PNG area; those were **fixed in 3.32.1** and the fixes are present in the snapshot we tested). We found no public advisory covering this missing error handling. ### Proof of concept **How the artifacts were produced:** upstream tree built with clang + AddressSanitizer, using the harness below (the tree currently has no image fuzz target; we wrote `FuzzImage.c` for this report). libFuzzer found the PNG abort within 55 executions. Observed (unpatched): ``` $ ./FuzzImage crash.min.png # 12 bytes libpng error: bad adaptive filter value ERROR: libFuzzer: deadly signal #7 png_longjmp.cold <- png_default_error <- png_error #10 png_read_row / png_read_image / png_read_png #13 winpr_read_png_from_buffer image.c:1208 #14 winpr_convert_from_png image.c:1323 #15 winpr_image_read_buffer image.c:750 $ ./FuzzImage bad.jpg # 62 bytes: FF D8 FF E0 0010 "JFIF" 00 + garbage SUMMARY: libFuzzer: fuzz target exited #7 winpr_convert_from_jpeg image.c:890 #8 winpr_image_read_buffer image.c:737 ``` **Reproduction harness (`poc/fuzz/FuzzImage.c`, inline):** ```c /* * libFuzzer harness for WinPR's image parser/writer (winpr_image). * * This is the path that consumes untrusted image data from a remote peer: * clipboard formats (image/png, image/jpeg, image/bmp, CF_DIB) are read via * winpr_image_read_buffer() and re-encoded via winpr_image_write_buffer() * (see winpr/libwinpr/clipboard/synthetic.c). GHSA-f3vg (PNG->CF_DIB OOB read) * lived on exactly this chain; the upstream tree has no dedicated image fuzzer. * * Input: raw image bytes (BMP/PNG/JPEG/WebP - format sniffed by the reader). */ #include <winpr/crt.h> #include <winpr/image.h> #include <stdlib.h> #include <string.h> int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) { if ((Size < 1) || (Size > (1u << 24))) return 0; wImage* img = winpr_image_new(); if (!img) return 0; const int rc = winpr_image_read_buffer(img, Data, Size); if (rc > 0) { const UINT32 formats[] = { WINPR_IMAGE_BITMAP, #if defined(WINPR_UTILS_IMAGE_PNG) WINPR_IMAGE_PNG, #endif #if defined(WINPR_UTILS_IMAGE_JPEG) WINPR_IMAGE_JPEG, #endif #if defined(WINPR_UTILS_IMAGE_WEBP) WINPR_IMAGE_WEBP, #endif }; for (size_t i = 0; i < ARRAYSIZE(formats); i++) { size_t osize = 0; void* out = winpr_image_write_buffer(img, formats[i], &osize); free(out); } } winpr_image_free(img, TRUE); return 0; } ``` (Place it in `winpr/libwinpr/utils/test/` as a fuzz target like the other `TestFuzz*` targets, or compile it directly against libwinpr; `winpr_image_read_buffer` is the same entry the clipboard conversion uses.) **Reproduction inputs (base64, decode: `echo <b64> | base64 -d > file`):** ``` # crash.min.png (12 bytes - PNG reader abort) iVBORw0KGgoAAAAA ``` ``` # bad.jpg (62 bytes - JPEG reader exit) /9j/4AAQSkZJRgABAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdAAAAAAAAAAAAAAAAAAAAAAAAAAA= ``` **Suggested fix (validated locally) - `0006-winpr-image-reader-error-handling.patch`:** ```diff --- a/winpr/libwinpr/utils/image.c +++ b/winpr/libwinpr/utils/image.c @@ -19,6 +19,7 @@ * limitations under the License. */ +#include <setjmp.h> #include <stdlib.h> #include <winpr/config.h> @@ -40,6 +41,23 @@ #undef INT32 #endif +#if defined(WINPR_UTILS_IMAGE_JPEG) +typedef struct +{ + struct jpeg_error_mgr pub; + jmp_buf jump; +} WINPR_JPEG_ERROR_MGR; + +/* libjpeg's default error handler calls exit(); longjmp back to the caller + * instead (the setjmp target is registered right after + * jpeg_create_compress()/jpeg_create_decompress(), see the libjpeg example). */ +static void winpr_jpeg_error_exit(j_common_ptr cinfo) +{ + WINPR_JPEG_ERROR_MGR* err = (WINPR_JPEG_ERROR_MGR*)cinfo->err; + longjmp(err->jump, 1); +} +#endif + #if defined(WINPR_UTILS_IMAGE_WEBP) #include <webp/encode.h> #include <webp/decode.h> @@ -809,10 +827,15 @@ return nullptr; /* Set up the error handler. */ - struct jpeg_error_mgr jerr = WINPR_C_ARRAY_INIT; - cinfo.err = jpeg_std_error(&jerr); - + WINPR_JPEG_ERROR_MGR jerr = WINPR_C_ARRAY_INIT; + cinfo.err = jpeg_std_error(&jerr.pub); + jerr.pub.error_exit = winpr_jpeg_error_exit; jpeg_create_compress(&cinfo); + + /* Set up error handling (must be after jpeg_create_compress). */ + if (setjmp(jerr.jump) != 0) + goto fail; + jpeg_mem_dest(&cinfo, &outbuffer, &outsize); cinfo.image_width = width; @@ -844,12 +867,18 @@ WINPR_ASSERT(outsize <= UINT32_MAX); *pSize = (UINT32)outsize; - -fail: jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); return outbuffer; + +fail: + /* Do not call libjpeg again after an error (a longjmp may have left the + * compressor in an undefined state); just clean up. */ + jpeg_destroy_compress(&cinfo); + free(outbuffer); + + return nullptr; #endif } @@ -879,12 +908,18 @@ return -1; #else struct jpeg_decompress_struct cinfo = WINPR_C_ARRAY_INIT; - struct jpeg_error_mgr jerr; + WINPR_JPEG_ERROR_MGR jerr = WINPR_C_ARRAY_INIT; SSIZE_T size = -1; BYTE* decomp_data = nullptr; - cinfo.err = jpeg_std_error(&jerr); + cinfo.err = jpeg_std_error(&jerr.pub); + jerr.pub.error_exit = winpr_jpeg_error_exit; jpeg_create_decompress(&cinfo); + + /* Set up error handling (must be after jpeg_create_decompress). */ + if (setjmp(jerr.jump) != 0) + goto fail; + jpeg_mem_src(&cinfo, comp_data, comp_data_bytes); if (jpeg_read_header(&cinfo, 1) != JPEG_HEADER_OK) @@ -1198,6 +1233,10 @@ if (!info_ptr) goto fail; + /* Set up error handling. */ + if (setjmp(png_jmpbuf(png_ptr))) + goto fail; + memory_reader_state.buffer = WINPR_CAST_CONST_PTR_AWAY(data, png_bytep); memory_reader_state.bufsize = (UINT32)SrcSize; memory_reader_state.current_pos = 0; ``` With the patch, both artifacts return -1 gracefully (no abort/exit, no ASan report) and valid PNG/BMP images still decode (no regression). ### Impact **Remote client DoS.** Any RDP server (or MITM) controlling clipboard content can terminate the client process: publish an image clipboard format whose payload is malformed (e.g. 12-byte PNG / truncated JPEG as above). The client aborts (SIGABRT) or exits inside `winpr_image_read_buffer()` during conversion - deterministic, no memory corruption, no code execution. User-visible impact: the session dies and unsaved state in co-operating local applications is lost; repeatedly offering the format can keep the client unusable. Class: CWE-248 (Uncaught Exception). Severity: low-moderate - we defer the final rating to you.
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| — | FreeRDP (c) | <= 3.32.1 | 3.22.2 | Patch available | GHSA-799q-hjgw-g55g |
- FreeRDP (c) Vendor— Affected <= 3.32.1 Fixed in 3.22.2 Patch available GHSA-799q-hjgw-g55g
Remediation
The affected data lists 3.22.2 as a fixed version for FreeRDP, but the report states that no patched version exists yet.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-799q-hjgw-g55g FreeRDP (c) Fixed in 3.22.2 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-799q-hjgw-g55g
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences