[FFmpeg-devel] [PATCH 4/5] ffmpeg: exit on corrupt packets or decoded frames if exit_on_error flag is present

Marton Balint cus at passwd.hu
Sun Oct 18 00:24:06 CEST 2015


Signed-off-by: Marton Balint <cus at passwd.hu>
---
 ffmpeg.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index 3a36af7..f6947f8 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1925,13 +1925,20 @@ int guess_input_channel_layout(InputStream *ist)
     return 1;
 }
 
-static void check_decode_result(int *got_output, int ret)
+static void check_decode_result(int *got_output, int ret, AVFrame *frame)
 {
     if (*got_output || ret<0)
         decode_error_stat[ret<0] ++;
 
     if (ret < 0 && exit_on_error)
         exit_program(1);
+
+    if (exit_on_error && *got_output && frame) {
+        if (av_frame_get_decode_error_flags(frame) || (frame->flags & AV_FRAME_FLAG_CORRUPT)) {
+            av_log(NULL, AV_LOG_FATAL, "Corrupt decoded frame\n");
+            exit_program(1);
+        }
+    }
 }
 
 static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
@@ -1956,7 +1963,7 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
         ret = AVERROR_INVALIDDATA;
     }
 
-    check_decode_result(got_output, ret);
+    check_decode_result(got_output, ret, decoded_frame);
 
     if (!*got_output || ret < 0)
         return ret;
@@ -2093,7 +2100,7 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)
                    ist->st->codec->has_b_frames);
     }
 
-    check_decode_result(got_output, ret);
+    check_decode_result(got_output, ret, decoded_frame);
 
     if (*got_output && ret >= 0) {
         if (ist->dec_ctx->width  != decoded_frame->width ||
@@ -2201,7 +2208,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
     int i, ret = avcodec_decode_subtitle2(ist->dec_ctx,
                                           &subtitle, got_output, pkt);
 
-    check_decode_result(got_output, ret);
+    check_decode_result(got_output, ret, NULL);
 
     if (ret < 0 || !*got_output) {
         if (!pkt->size)
@@ -3770,6 +3777,11 @@ static int process_input(int file_index)
     if (ist->discard)
         goto discard_packet;
 
+    if (exit_on_error && (pkt.flags & AV_PKT_FLAG_CORRUPT)) {
+        av_log(NULL, AV_LOG_FATAL, "Corrupt input packet\n");
+        exit_program(1);
+    }
+
     if (debug_ts) {
         av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s "
                "next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%s off_time:%s\n",
-- 
2.1.4



More information about the ffmpeg-devel mailing list