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
This commit is contained in:
@@ -216,6 +216,16 @@ 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) {
|
||||
av_log(NULL, AV_LOG_WARNING,
|
||||
"fd 0 is not an open file descriptor, stdin interaction disabled\n");
|
||||
stdin_interaction = 0;
|
||||
}
|
||||
|
||||
if (stdin_interaction) {
|
||||
struct termios tty;
|
||||
if (tcgetattr (0, &tty) == 0) {
|
||||
|
||||
Reference in New Issue
Block a user