]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/v4l2_buffers: Fix infinite loop
authorAndriy Gelman <andriy.gelman@gmail.com>
Sun, 27 Oct 2019 04:19:46 +0000 (00:19 -0400)
committerAman Gupta <aman@tmm1.net>
Fri, 1 Nov 2019 22:19:55 +0000 (15:19 -0700)
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.

Signed-off-by: Aman Gupta <aman@tmm1.net>
libavcodec/v4l2_buffers.c

index e301dcd6bd500ccde81a281fda1c733f326e838f..dc1b9eaf241bb98a588ac7caf53c04765cce2a5e 100644 (file)
@@ -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