[FFmpeg-devel] [PATCH] Fixing rare dshow input crash

Alexey Potakhov alex at potahov.com
Thu Sep 5 01:08:12 EEST 2019


In some rare cases when IAMStreamConfig_GetStreamCaps returns an error
avformat_open_input() crashes with access violation.
-------------- next part --------------
From c15f00b4e70c60ac38009905b4d2c2f3032967a6 Mon Sep 17 00:00:00 2001
From: Alexey Potakhov <alex at 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(-)

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);
-- 
2.21.0.windows.1



More information about the ffmpeg-devel mailing list