diff mbox

[FFmpeg-devel,3/4] hwcontext: Don't segfault on invalid arguments to transfer

Message ID 20180521223511.20395-3-sw@jkqxz.net
State New
Headers show

Commit Message

Mark Thompson May 21, 2018, 10:35 p.m. UTC
The code previously assumed that src->hw_frames_ctx was necessarily set
if dst->buf wasn't.  Using non-refcounted hardware frames is not allowed
here, but we can return an error in that case.
---
 libavutil/hwcontext.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 745016ed7e..5859443cf6 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -441,8 +441,12 @@  int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
     AVHWFramesContext *ctx;
     int ret;
 
-    if (!dst->buf[0])
-        return transfer_data_alloc(dst, src, flags);
+    if (!dst->buf[0]) {
+        if (src->hw_frames_ctx)
+            return transfer_data_alloc(dst, src, flags);
+        else
+            return AVERROR(EINVAL);
+    }
 
     if (src->hw_frames_ctx) {
         ctx = (AVHWFramesContext*)src->hw_frames_ctx->data;