Blame SOURCES/Fixed-CVE-2020-11521-Out-of-bounds-write-in-planar-c.patch

b460d2
From d9f3c98918912de94af033fbab9578188ad46cf7 Mon Sep 17 00:00:00 2001
b460d2
From: akallabeth <akallabeth@posteo.net>
b460d2
Date: Mon, 30 Mar 2020 18:18:12 +0200
b460d2
Subject: [PATCH] Fixed CVE-2020-11521: Out of bounds write in planar codec.
b460d2
b460d2
Thanks to Sunglin and HuanGMz from Knownsec 404
b460d2
---
b460d2
 libfreerdp/codec/planar.c | 15 ++++++++-------
b460d2
 libfreerdp/core/orders.c  |  6 ++++++
b460d2
 2 files changed, 14 insertions(+), 7 deletions(-)
b460d2
b460d2
diff --git a/libfreerdp/codec/planar.c b/libfreerdp/codec/planar.c
b460d2
index 98f2495e2..34c48d786 100644
b460d2
--- a/libfreerdp/codec/planar.c
b460d2
+++ b/libfreerdp/codec/planar.c
b460d2
@@ -42,10 +42,9 @@ static INLINE BYTE* freerdp_bitmap_planar_delta_encode_plane(
b460d2
 static INLINE INT32 planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize,
b460d2
         UINT32 nWidth, UINT32 nHeight)
b460d2
 {
b460d2
+	UINT32 used = 0;
b460d2
 	UINT32 x, y;
b460d2
 	BYTE controlByte;
b460d2
-	const BYTE* pRLE = pSrcData;
b460d2
-	const BYTE* pEnd = &pSrcData[SrcSize];
b460d2
 
b460d2
 	for (y = 0; y < nHeight; y++)
b460d2
 	{
b460d2
@@ -54,10 +53,10 @@ static INLINE INT32 planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize,
b460d2
 			int cRawBytes;
b460d2
 			int nRunLength;
b460d2
 
b460d2
-			if (pRLE >= pEnd)
b460d2
+			if (used >= SrcSize)
b460d2
 				return -1;
b460d2
 
b460d2
-			controlByte = *pRLE++;
b460d2
+			controlByte = pSrcData[used++];
b460d2
 			nRunLength = PLANAR_CONTROL_BYTE_RUN_LENGTH(controlByte);
b460d2
 			cRawBytes = PLANAR_CONTROL_BYTE_RAW_BYTES(controlByte);
b460d2
 
b460d2
@@ -72,19 +71,21 @@ static INLINE INT32 planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize,
b460d2
 				cRawBytes = 0;
b460d2
 			}
b460d2
 
b460d2
-			pRLE += cRawBytes;
b460d2
+			used += cRawBytes;
b460d2
 			x += cRawBytes;
b460d2
 			x += nRunLength;
b460d2
 
b460d2
 			if (x > nWidth)
b460d2
 				return -1;
b460d2
 
b460d2
-			if (pRLE > pEnd)
b460d2
+			if (used > SrcSize)
b460d2
 				return -1;
b460d2
 		}
b460d2
 	}
b460d2
 
b460d2
-	return (INT32)(pRLE - pSrcData);
b460d2
+	if (used > INT32_MAX)
b460d2
+		return -1;
b460d2
+	return (INT32)used;
b460d2
 }
b460d2
 
b460d2
 static INLINE INT32 planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 SrcSize,
b460d2
diff --git a/libfreerdp/core/orders.c b/libfreerdp/core/orders.c
b460d2
index 9f3489f17..e44f0dead 100644
b460d2
--- a/libfreerdp/core/orders.c
b460d2
+++ b/libfreerdp/core/orders.c
b460d2
@@ -1961,6 +1961,9 @@ static CACHE_BITMAP_ORDER* update_read_cache_bitmap_order(rdpUpdate* update, wSt
b460d2
 		}
b460d2
 	}
b460d2
 
b460d2
+	if (cache_bitmap->bitmapLength == 0)
b460d2
+		goto fail;
b460d2
+
b460d2
 	if (Stream_GetRemainingLength(s) < cache_bitmap->bitmapLength)
b460d2
 		goto fail;
b460d2
 
b460d2
@@ -2095,6 +2098,9 @@ static CACHE_BITMAP_V2_ORDER* update_read_cache_bitmap_v2_order(rdpUpdate* updat
b460d2
 		}
b460d2
 	}
b460d2
 
b460d2
+	if (cache_bitmap_v2->bitmapLength == 0)
b460d2
+		goto fail;
b460d2
+
b460d2
 	if (Stream_GetRemainingLength(s) < cache_bitmap_v2->bitmapLength)
b460d2
 		goto fail;
b460d2
 
b460d2
-- 
b460d2
2.26.2
b460d2