[PR] fftools/ffmpeg_demux: provide a default fallback filename in dump_attachment (PR #23840)

rcombs via ffmpeg-devel <[email protected]> Sat, 18 Jul 2026 07:23:13 -0000
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <178435939427.59.2922026960851760563@29965ddac10e>
PR #23840 opened by rcombs
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23840
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23840.patch

Optimally this would be made *mostly* moot by #23342, but that seems to still have some windows kinks to work out, and this goes a bit further: even if a filename is considered "unsafe" (the definition of which might vary depending on the platform), or if an attachment has no filename at all (eg dumping extradata from a non-attachment stream), we can still synthesize a safe default filename and write to that. It's not a substitute for permitting more entirely innocuous filenames (eg ones with spaces, or non-abusive unicode usage), but it should serve to soften this particular sharp edge a bit for now.


>From ef187ccd11815955e43fa205bf4831847ab76e16 Mon Sep 17 00:00:00 2001
From: rcombs <[email protected]>
Date: Sat, 18 Jul 2026 00:10:55 -0700
Subject: [PATCH] fftools/ffmpeg_demux: provide a default fallback filename in
 dump_attachment

---
 fftools/ffmpeg_demux.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 8a165faf1d..1af67ca829 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -2177,21 +2177,27 @@ static int dump_attachment(InputStream *ist, const char *filename)
     int ret;
     AVIOContext *out = NULL;
     const AVDictionaryEntry *e;
+    char default_filename[64];
+    snprintf(default_filename, sizeof(default_filename), "infile%i-stream%i.bin",
+             ist->file->index, ist->index);
 
     if (!st->codecpar->extradata_size) {
         av_log(ist, AV_LOG_WARNING, "No extradata to dump.\n");
         return 0;
     }
     if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0))) {
-        filename = e->value;
-        if (!safe_filename(filename, 0)) {
-            av_log(ist, AV_LOG_ERROR, "Filename %s is unsafe\n", filename);
-            return AVERROR(EINVAL);
+        if (safe_filename(e->value, 0)) {
+            filename = e->value;
+        } else {
+            av_log(ist, AV_LOG_WARNING, "Filename %s is unsafe; using default: %s\n",
+                   e->value, default_filename);
+            filename = default_filename;
         }
     }
     if (!*filename) {
-        av_log(ist, AV_LOG_FATAL, "No filename specified and no 'filename' tag");
-        return AVERROR(EINVAL);
+        av_log(ist, AV_LOG_WARNING, "No filename specified and no 'filename' tag; "
+               "using default: %s\n", default_filename);
+        filename = default_filename;
     }
 
     ret = assert_file_overwrite(filename);
-- 
2.52.0

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