diff mbox

[FFmpeg-devel] Fixing rare dshow input crash

Message ID CAKAeJacsC17yeD5JScijSY848tZ2=ataO_Noww3j3meY+j=s0A@mail.gmail.com
State Superseded
Headers show

Commit Message

Alexey Potakhov Sept. 4, 2019, 10:08 p.m. UTC
In some rare cases when IAMStreamConfig_GetStreamCaps returns an error
avformat_open_input() crashes with access violation.
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(-)

Comments

Carl Eugen Hoyos Sept. 4, 2019, 10:22 p.m. UTC | #1
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
diff mbox

Patch

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);