PR #23556 opened by Zhao Zhili (quink)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23556
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23556.patch

When the parent process closes stdin before launching ffmpeg, fd 0 is
left invalid. The first opened input file then reuses fd 0, and the
read_key() poll in the transcode loop reads from that input instead of
the terminal, stealing bytes and corrupting the stream.

Fixes #23539

# Summary of changes

Briefly describe what this PR does and why.

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



>From dad49119bc6ae000251f6efd2eefa897749d69be Mon Sep 17 00:00:00 2001
From: Zhao Zhili <[email protected]>
Date: Mon, 22 Jun 2026 20:36:10 +0800
Subject: [PATCH] fftools/ffmpeg: disable stdin interaction when fd 0 is closed

When the parent process closes stdin before launching ffmpeg, fd 0 is
left invalid. The first opened input file then reuses fd 0, and the
read_key() poll in the transcode loop reads from that input instead of
the terminal, stealing bytes and corrupting the stream.

Fixes #23539
---
 fftools/ffmpeg.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index b394243f59..1c71c6f034 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -216,6 +216,13 @@ void term_init(void)
 #endif
 
 #if HAVE_TERMIOS_H
+    /* A closed fd 0 is later reused by the first opened input file. read_key()
+     * would then read from that input instead of the terminal and corrupt the
+     * stream, so disable interaction when fd 0 is not an open descriptor.
+     */
+    if (stdin_interaction && fcntl(0, F_GETFD) == -1)
+        stdin_interaction = 0;
+
     if (stdin_interaction) {
         struct termios tty;
         if (tcgetattr (0, &tty) == 0) {
-- 
2.52.0

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

Reply via email to