From 5e96a5dbefc8daadabb02480b082e6bd08348596 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Fri, 10 Feb 2012 02:52:48 -0800 Subject: [PATCH] add more param checks to WebPPictureDistortion() and use the proper alpha flag too. Change-Id: I664c6c9dbcc747495bf20b3da95d00e1120b5baf --- src/enc/picture.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/enc/picture.c b/src/enc/picture.c index 10b896e2..89c216e6 100644 --- a/src/enc/picture.c +++ b/src/enc/picture.c @@ -670,10 +670,20 @@ int WebPPictureDistortion(const WebPPicture* const pic1, int type, float result[5]) { int c; DistoStats stats[5]; + int has_alpha; - if (pic1->width != pic2->width || - pic1->height != pic2->height || - (pic1->a == NULL) != (pic2->a == NULL)) { + if (pic1 == NULL || pic2 == NULL || + pic1->width != pic2->width || pic1->height != pic2->height || + pic1->y == NULL || pic2->y == NULL || + pic1->u == NULL || pic2->u == NULL || + pic1->v == NULL || pic2->v == NULL || + result == NULL) { + return 0; + } + + has_alpha = !!(pic1->colorspace & WEBP_CSP_ALPHA_BIT); + if (has_alpha != !!(pic2->colorspace & WEBP_CSP_ALPHA_BIT) || + (has_alpha && (pic1->a == NULL || pic2->a == NULL))) { return 0; } @@ -689,7 +699,7 @@ int WebPPictureDistortion(const WebPPicture* const pic1, pic2->v, pic2->uv_stride, (pic1->width + 1) >> 1, (pic1->height + 1) >> 1, &stats[2]); - if (pic1->a != NULL) { + if (has_alpha) { VP8SSIMAccumulatePlane(pic1->a, pic1->a_stride, pic2->a, pic2->a_stride, pic1->width, pic1->height, &stats[3]);