]> granicus.if.org Git - libvpx/commitdiff
vpx_image: clear user provided vpx_image_t early
authorJames Zern <jzern@google.com>
Fri, 9 Apr 2021 00:34:16 +0000 (17:34 -0700)
committerJames Zern <jzern@google.com>
Fri, 9 Apr 2021 00:34:16 +0000 (17:34 -0700)
this avoids uninitialized values and potential misuse of them which
could lead to a crash should the function fail

this is the same fix that was applied in libaom:
d0cac70b5 Fix a free on invalid ptr when img allocation fails

Bug: webm:1722
Change-Id: If7a8d08c4b010f12e2e1d848613c0fa7328f1f9c

vpx/src/vpx_image.c

index ff496b5d34f143810428a9aa87b4c072153ffded..2b7411f94fb432e49db6ca33f648f6cb7b5573b3 100644 (file)
@@ -24,6 +24,8 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img, vpx_img_fmt_t fmt,
   unsigned int stride_in_bytes;
   int align;
 
+  if (img != NULL) memset(img, 0, sizeof(vpx_image_t));
+
   /* Treat align==0 like align==1 */
   if (!buf_align) buf_align = 1;
 
@@ -88,8 +90,6 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img, vpx_img_fmt_t fmt,
     if (!img) goto fail;
 
     img->self_allocd = 1;
-  } else {
-    memset(img, 0, sizeof(vpx_image_t));
   }
 
   img->img_data = img_data;