video: Fix possible overrun when iterating comp[] array
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 19 Apr 2022 15:05:05 +0000 (11:05 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 19 Apr 2022 15:12:42 +0000 (11:12 -0400)
Fix 2 iterations that can overrun the array if the number of component is
equal to the size of the array.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2239>

subprojects/gst-plugins-base/gst-libs/gst/video/video-format.c
subprojects/gst-plugins-base/gst-libs/gst/video/video-frame.c

index 09a5776..286051f 100644 (file)
@@ -7743,7 +7743,7 @@ gst_video_format_info_extrapolate_stride (const GstVideoFormatInfo * finfo,
    * number of component on the first plane against the number of component on
    * the current plane. */
   estride = 0;
-  for (i = 0; comp[i] >= 0; i++)
+  for (i = 0; i < GST_VIDEO_MAX_COMPONENTS && comp[i] >= 0; i++)
     estride += GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (finfo, comp[i], stride);
 
   return estride;
index d920912..cbd6369 100644 (file)
@@ -294,7 +294,7 @@ scale_tile_shifts (const GstVideoFormatInfo * finfo, gint plane, guint * ws,
   /* for each additional component in the same plane, double the tile width,
    * this should provide the appropriate tile size when the tile size varies
    * base on the subsampling. */
-  for (i = 1; comp[i] >= 0; i++)
+  for (i = 1; i < GST_VIDEO_MAX_COMPONENTS && comp[i] >= 0; i++)
     *ws += 1;
 }