Fixed NSC SSE argument checks.
authorArmin Novak <armin.novak@thincast.com>
Thu, 7 Feb 2019 11:02:28 +0000 (12:02 +0100)
committerArmin Novak <armin.novak@thincast.com>
Fri, 5 Apr 2019 07:13:24 +0000 (09:13 +0200)
libfreerdp/codec/nsc_sse2.c

index 966525f..273f39e 100644 (file)
@@ -35,7 +35,7 @@
 #include "nsc_types.h"
 #include "nsc_sse2.h"
 
-static void nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context,
+static BOOL nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context,
         const BYTE* data, UINT32 scanline)
 {
        UINT16 x;
@@ -55,10 +55,20 @@ static void nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context,
        __m128i co_val;
        __m128i cg_val;
        UINT32 tempWidth;
+
+       if (!context || !data || (scanline == 0))
+               return FALSE;
+
        tempWidth = ROUND_UP_TO(context->width, 8);
        rw = (context->ChromaSubsamplingLevel > 0 ? tempWidth : context->width);
        ccl = context->ColorLossLevel;
 
+       if (context->priv->PlaneBuffersLength < rw * scanline)
+               return FALSE;
+
+       if (rw < scanline * 2)
+               return FALSE;
+
        for (y = 0; y < context->height; y++)
        {
                src = data + (context->height - 1 - y) * scanline;
@@ -332,6 +342,8 @@ static void nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context,
                CopyMemory(coplane, coplane - rw, rw);
                CopyMemory(cgplane, cgplane - rw, rw);
        }
+
+       return TRUE;
 }
 
 static void nsc_encode_subsampling_sse2(NSC_CONTEXT* context)
@@ -388,12 +400,11 @@ static void nsc_encode_subsampling_sse2(NSC_CONTEXT* context)
 static BOOL nsc_encode_sse2(NSC_CONTEXT* context, const BYTE* data,
                             UINT32 scanline)
 {
-       nsc_encode_argb_to_aycocg_sse2(context, data, scanline);
+       if (!nsc_encode_argb_to_aycocg_sse2(context, data, scanline))
+               return FALSE;
 
        if (context->ChromaSubsamplingLevel > 0)
-       {
                nsc_encode_subsampling_sse2(context);
-       }
 
        return TRUE;
 }