From 0d78b871e57de60e00823298641f6901fd09f173 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Mon, 4 Nov 2024 10:10:40 +0100 Subject: [PATCH] [core,fastpath] fix bulk max size the type is UINT16 so the maximum size can only be UINT16_MAX --- libfreerdp/codec/bulk.c | 15 ++++++++------- libfreerdp/codec/bulk.h | 2 +- libfreerdp/core/fastpath.c | 5 ++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libfreerdp/codec/bulk.c b/libfreerdp/codec/bulk.c index 7a2005b12..c804f00bc 100644 --- a/libfreerdp/codec/bulk.c +++ b/libfreerdp/codec/bulk.c @@ -37,7 +37,7 @@ struct rdp_bulk { ALIGN64 rdpContext* context; ALIGN64 UINT32 CompressionLevel; - ALIGN64 UINT32 CompressionMaxSize; + ALIGN64 UINT16 CompressionMaxSize; ALIGN64 MPPC_CONTEXT* mppcSend; ALIGN64 MPPC_CONTEXT* mppcRecv; ALIGN64 NCRUSH_CONTEXT* ncrushRecv; @@ -83,14 +83,15 @@ static UINT32 bulk_compression_level(rdpBulk* WINPR_RESTRICT bulk) bulk->CompressionLevel = (settings->CompressionLevel >= PACKET_COMPR_TYPE_RDP61) ? PACKET_COMPR_TYPE_RDP61 : settings->CompressionLevel; + WINPR_ASSERT(bulk->CompressionLevel <= UINT16_MAX); return bulk->CompressionLevel; } -UINT32 bulk_compression_max_size(rdpBulk* WINPR_RESTRICT bulk) +UINT16 bulk_compression_max_size(rdpBulk* WINPR_RESTRICT bulk) { WINPR_ASSERT(bulk); - bulk_compression_level(bulk); - bulk->CompressionMaxSize = (bulk->CompressionLevel < PACKET_COMPR_TYPE_64K) ? 8192 : 65536; + (void)bulk_compression_level(bulk); + bulk->CompressionMaxSize = (bulk->CompressionLevel < PACKET_COMPR_TYPE_64K) ? 8192 : UINT16_MAX; return bulk->CompressionMaxSize; } @@ -161,7 +162,7 @@ int bulk_decompress(rdpBulk* WINPR_RESTRICT bulk, const BYTE* WINPR_RESTRICT pSr rdpMetrics* metrics = bulk->context->metrics; WINPR_ASSERT(metrics); - bulk_compression_max_size(bulk); + (void)bulk_compression_max_size(bulk); const UINT32 type = flags & BULK_COMPRESSION_TYPE_MASK; if (flags & BULK_COMPRESSION_FLAGS_MASK) @@ -259,8 +260,8 @@ int bulk_compress(rdpBulk* WINPR_RESTRICT bulk, const BYTE* WINPR_RESTRICT pSrcD } *pDstSize = sizeof(bulk->OutputBuffer); - bulk_compression_level(bulk); - bulk_compression_max_size(bulk); + (void)bulk_compression_level(bulk); + (void)bulk_compression_max_size(bulk); switch (bulk->CompressionLevel) { diff --git a/libfreerdp/codec/bulk.h b/libfreerdp/codec/bulk.h index c1dfeb302..fece0d669 100644 --- a/libfreerdp/codec/bulk.h +++ b/libfreerdp/codec/bulk.h @@ -28,7 +28,7 @@ typedef struct rdp_bulk rdpBulk; #define BULK_COMPRESSION_FLAGS_MASK 0xE0 #define BULK_COMPRESSION_TYPE_MASK 0x0F -FREERDP_LOCAL UINT32 bulk_compression_max_size(rdpBulk* WINPR_RESTRICT bulk); +FREERDP_LOCAL UINT16 bulk_compression_max_size(rdpBulk* WINPR_RESTRICT bulk); FREERDP_LOCAL int bulk_decompress(rdpBulk* WINPR_RESTRICT bulk, const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, const BYTE** WINPR_RESTRICT ppDstData, diff --git a/libfreerdp/core/fastpath.c b/libfreerdp/core/fastpath.c index 8a7e61386..dbf7d0fc6 100644 --- a/libfreerdp/core/fastpath.c +++ b/libfreerdp/core/fastpath.c @@ -1189,9 +1189,8 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s if (settings->CompressionEnabled && !skipCompression) { - const UINT32 CompressionMaxSize = bulk_compression_max_size(rdp->bulk); - WINPR_ASSERT(CompressionMaxSize <= UINT16_MAX); - maxLength = (maxLength < CompressionMaxSize) ? maxLength : (UINT16)(CompressionMaxSize); + const UINT16 CompressionMaxSize = bulk_compression_max_size(rdp->bulk); + maxLength = (maxLength < CompressionMaxSize) ? maxLength : CompressionMaxSize; maxLength -= 20; }