PR #23785 opened by michaelni
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23785
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23785.patch

This is a generic recursion limit that is not specific to a demuxer
it does change public API which makes this unsuitable for backporting

Fixes: self_ref.ffconcat

Reported-by: Yuhao Jiang <[email protected]>

Signed-off-by: Michael Niedermayer <[email protected]>

This is a more generic solution to 
https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23784 but it is not easy to 
backport due to API extension
These patches where posted previously and then forgotton



>From 55fe8ec8e82b72ce403df5de7d3c860664e38130 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <[email protected]>
Date: Mon, 7 Jul 2025 02:44:19 +0200
Subject: [PATCH] avformat: Add recursion limit

This is a generic recursion limit that is not specific to a demuxer
it does change public API which makes this unsuitable for backporting

Fixes: self_ref.ffconcat

Reported-by: Yuhao Jiang <[email protected]>

Signed-off-by: Michael Niedermayer <[email protected]>
---
 libavformat/avformat.c      | 5 +++++
 libavformat/avformat.h      | 9 +++++++++
 libavformat/options_table.h | 1 +
 libavformat/version.h       | 2 +-
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 0f9d50a99d..db9fad2f2d 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -896,6 +896,11 @@ int ff_copy_whiteblacklists(AVFormatContext *dst, const 
AVFormatContext *src)
             *(char **)((char*)dst + offsets[i]) = dst_str;
         }
     }
+    if (src->recursion_limit <= 0) {
+        av_log(dst, AV_LOG_ERROR, "Too deep recursion\n");
+        return AVERROR_INVALIDDATA;
+    }
+    dst->recursion_limit = src->recursion_limit - 1;
     return 0;
 }
 
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index ef2b08c4f3..2ebe889b54 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1944,6 +1944,15 @@ typedef struct AVFormatContext {
      * Name of this format context, only used for logging purposes.
      */
     char *name;
+
+    /**
+     * Depth recursion limit,
+     *
+     * The maximum recursion depth that a Demuxer can open a Demuxer within 
itself.
+     *
+     * - demuxing: Set by user
+     */
+    int recursion_limit;
 } AVFormatContext;
 
 /**
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index bedec2a8a9..ffad27b457 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -107,6 +107,7 @@ static const AVOption avformat_options[] = {
 {"skip_estimate_duration_from_pts", "skip duration calculation in 
estimate_timings_from_pts", OFFSET(skip_estimate_duration_from_pts), 
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D},
 {"max_probe_packets", "Maximum number of packets to probe a codec", 
OFFSET(max_probe_packets), AV_OPT_TYPE_INT, { .i64 = 2500 }, 0, INT_MAX, D },
 {"duration_probesize", "Maximum number of bytes to probe the durations of the 
streams in estimate_timings_from_pts", OFFSET(duration_probesize), 
AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, (double)INT64_MAX, D},
+{"recursion_limit", "Maximum number of times a demuxer can recursively be 
opened", OFFSET(recursion_limit), AV_OPT_TYPE_INT, {.i64 = 10 }, 0, INT64_MAX, 
D},
 {NULL},
 };
 
diff --git a/libavformat/version.h b/libavformat/version.h
index af7d0a1024..e2634b85ae 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
 
 #include "version_major.h"
 
-#define LIBAVFORMAT_VERSION_MINOR   4
+#define LIBAVFORMAT_VERSION_MINOR   5
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to