diff mbox

[FFmpeg-devel,1/2] avcodec/v4l2_buffers: Fix infinite loop

Message ID 20191027041947.24126-1-andriy.gelman@gmail.com
State Accepted
Commit 1aec1183f3e82e9aa20fe23d961f663c1efc45fb
Headers show

Commit Message

Andriy Gelman Oct. 27, 2019, 4:19 a.m. UTC
From: Andriy Gelman <andriy.gelman@gmail.com>

This part of the code counts the number of planes returned by the v4l2
device for each queried capture/output buffer.
When testing the GPU h264 encoder on Nvidia's Jetson Nano, this caused an
infinite loop because avbuf->buf.length included some empty buffers (i.e.
where avbuf->buf.m.planes[i].length = 0), meaning that the counter was
never incremented and break was never reached.
This is fixed in the commit by using a well defined iteration range.
---
 libavcodec/v4l2_buffers.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Andriy Gelman Nov. 1, 2019, 1:33 p.m. UTC | #1
On Sun, 27. Oct 00:19, Andriy Gelman wrote:
> From: Andriy Gelman <andriy.gelman@gmail.com>
> 
> This part of the code counts the number of planes returned by the v4l2
> device for each queried capture/output buffer.
> When testing the GPU h264 encoder on Nvidia's Jetson Nano, this caused an
> infinite loop because avbuf->buf.length included some empty buffers (i.e.
> where avbuf->buf.m.planes[i].length = 0), meaning that the counter was
> never incremented and break was never reached.
> This is fixed in the commit by using a well defined iteration range.
> ---
>  libavcodec/v4l2_buffers.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
> index e301dcd6bd..dc1b9eaf24 100644
> --- a/libavcodec/v4l2_buffers.c
> +++ b/libavcodec/v4l2_buffers.c
> @@ -511,11 +511,9 @@ int ff_v4l2_buffer_initialize(V4L2Buffer* avbuf, int index)
>  
>      if (V4L2_TYPE_IS_MULTIPLANAR(ctx->type)) {
>          avbuf->num_planes = 0;
> -        for (;;) {
> -            /* in MP, the V4L2 API states that buf.length means num_planes */
> -            if (avbuf->num_planes >= avbuf->buf.length)
> -                break;
> -            if (avbuf->buf.m.planes[avbuf->num_planes].length)
> +        /* in MP, the V4L2 API states that buf.length means num_planes */
> +        for (i = 0; i < avbuf->buf.length; i++) {
> +            if (avbuf->buf.m.planes[i].length)
>                  avbuf->num_planes++;
>          }
>      } else
> -- 
> 2.23.0
> 

ping
Aman Gupta Nov. 1, 2019, 10:21 p.m. UTC | #2
On Fri, Nov 1, 2019 at 6:39 AM Andriy Gelman <andriy.gelman@gmail.com>
wrote:

> On Sun, 27. Oct 00:19, Andriy Gelman wrote:
> > From: Andriy Gelman <andriy.gelman@gmail.com>
> >
> > This part of the code counts the number of planes returned by the v4l2
> > device for each queried capture/output buffer.
> > When testing the GPU h264 encoder on Nvidia's Jetson Nano, this caused an
> > infinite loop because avbuf->buf.length included some empty buffers (i.e.
> > where avbuf->buf.m.planes[i].length = 0), meaning that the counter was
> > never incremented and break was never reached.
> > This is fixed in the commit by using a well defined iteration range.
> > ---
> >  libavcodec/v4l2_buffers.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
> > index e301dcd6bd..dc1b9eaf24 100644
> > --- a/libavcodec/v4l2_buffers.c
> > +++ b/libavcodec/v4l2_buffers.c
> > @@ -511,11 +511,9 @@ int ff_v4l2_buffer_initialize(V4L2Buffer* avbuf,
> int index)
> >
> >      if (V4L2_TYPE_IS_MULTIPLANAR(ctx->type)) {
> >          avbuf->num_planes = 0;
> > -        for (;;) {
> > -            /* in MP, the V4L2 API states that buf.length means
> num_planes */
> > -            if (avbuf->num_planes >= avbuf->buf.length)
> > -                break;
> > -            if (avbuf->buf.m.planes[avbuf->num_planes].length)
> > +        /* in MP, the V4L2 API states that buf.length means num_planes
> */
> > +        for (i = 0; i < avbuf->buf.length; i++) {
> > +            if (avbuf->buf.m.planes[i].length)
> >                  avbuf->num_planes++;
> >          }
> >      } else
> > --
> > 2.23.0
> >
>
> ping
>

Applied, thank you!


>
> --
> Andriy
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox

Patch

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index e301dcd6bd..dc1b9eaf24 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -511,11 +511,9 @@  int ff_v4l2_buffer_initialize(V4L2Buffer* avbuf, int index)
 
     if (V4L2_TYPE_IS_MULTIPLANAR(ctx->type)) {
         avbuf->num_planes = 0;
-        for (;;) {
-            /* in MP, the V4L2 API states that buf.length means num_planes */
-            if (avbuf->num_planes >= avbuf->buf.length)
-                break;
-            if (avbuf->buf.m.planes[avbuf->num_planes].length)
+        /* in MP, the V4L2 API states that buf.length means num_planes */
+        for (i = 0; i < avbuf->buf.length; i++) {
+            if (avbuf->buf.m.planes[i].length)
                 avbuf->num_planes++;
         }
     } else