From 1a6c109c99a634e51cef645c524a2f2a2acf1cdf Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 8 Aug 2022 16:40:21 -0700 Subject: [PATCH] WebPPictureHasTransparency: add missing pointer check in the case of use_argb, alpha_offset may be non-zero which would cause the null pointer check in CheckNonOpaque to pass fixes a potential crash with invalid width/height set or an integer sanitizer warning when passing a zeroed picture: src/enc/picture_csp_enc.c:73:57: runtime error: applying non-zero offset 3 to null pointer Change-Id: I9d499bba12c65ad5c65d8f9f3c8ee9298ac6081a --- src/enc/picture_csp_enc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/enc/picture_csp_enc.c b/src/enc/picture_csp_enc.c index fabebcf2..d23ac776 100644 --- a/src/enc/picture_csp_enc.c +++ b/src/enc/picture_csp_enc.c @@ -70,9 +70,12 @@ int WebPPictureHasTransparency(const WebPPicture* picture) { if (picture == NULL) return 0; if (picture->use_argb) { const int alpha_offset = ALPHA_OFFSET; - return CheckNonOpaque((const uint8_t*)picture->argb + alpha_offset, - picture->width, picture->height, - 4, picture->argb_stride * sizeof(*picture->argb)); + if (picture->argb != NULL) { + return CheckNonOpaque((const uint8_t*)picture->argb + alpha_offset, + picture->width, picture->height, + 4, picture->argb_stride * sizeof(*picture->argb)); + } + return 0; } return CheckNonOpaque(picture->a, picture->width, picture->height, 1, picture->a_stride);