[FFmpeg-devel] Fixing rare dshow input crash

Submitted by Alexey Potakhov on Sept. 5, 2019, 8:48 p.m.

Details

Message ID CAKAeJadwg-yx85o-RpJUzbOc7wozBBU6LGt7Grp5CcGxCy01sw@mail.gmail.com
State New
Headers show

Commit Message

Alexey Potakhov Sept. 5, 2019, 8:48 p.m.
re-sending without tabs.

On Wed, Sep 4, 2019 at 6:22 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
>
> Am Do., 5. Sept. 2019 um 00:08 Uhr schrieb Alexey Potakhov <alex@potahov.com>:
>
> > In some rare cases when IAMStreamConfig_GetStreamCaps returns
> > an error avformat_open_input() crashes with access violation.
>
> Tabs are rejected by our repository, please remove them and resend.
>
> Carl Eugen
> _______________________________________________
> 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".
From c15f00b4e70c60ac38009905b4d2c2f3032967a6 Mon Sep 17 00:00:00 2001
From: Alexey Potakhov <alex@potahov.com>
Date: Wed, 4 Sep 2019 17:54:24 -0400
Subject: [PATCH] Fixing rare dshow input crash

---
 libavdevice/dshow.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c
index d7f5bd7069..d1ae63b310 100644
--- a/libavdevice/dshow.c
+++ b/libavdevice/dshow.c
@@ -340,8 +340,10 @@  dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
 
     for (i = 0; i < n && !format_set; i++) {
         r = IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps);
-        if (r != S_OK)
-            goto next;
+        if (r != S_OK) {
+            type = NULL;
+            goto next;
+        }
 #if DSHOWDEBUG
         ff_print_AM_MEDIA_TYPE(type);
 #endif
@@ -450,9 +452,11 @@  dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype,
             goto next;
         format_set = 1;
 next:
-        if (type->pbFormat)
-            CoTaskMemFree(type->pbFormat);
-        CoTaskMemFree(type);
+        if (type) {
+            if (type->pbFormat)
+                CoTaskMemFree(type->pbFormat);
+            CoTaskMemFree(type);
+        }
     }
 end:
     IAMStreamConfig_Release(config);