Skip to content

Commit 5c537be

Browse files
committed
mtmd: fix double-close of ffmpeg/ffprobe stdin in video helper
mtmd_helper_video::feed_stdin() closes the FILE returned by subprocess_stdin(), which is sp->stdin_file. The local fclose() leaves sp->stdin_file dangling (still non-NULL), so the subsequent subprocess_destroy() fclose()s the same FILE a second time, corrupting the heap and aborting the process ("corrupted double-linked list" / "corrupted size vs. prev_size"). This reproduces on the server's base64 input_video path (every probe()/start_ffmpeg() feeds the buffer through stdin); the CLI --video <file> path is unaffected because it never spawns the stdin feeder. Clear sp->stdin_file after fclose() so subprocess_destroy() skips it. Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 1705d43 commit 5c537be

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

tools/mtmd/mtmd-helper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,11 @@ struct mtmd_helper_video {
643643
size_t written = fwrite(input_buf.data(), 1, input_buf.size(), f);
644644
LOG_DBG("%s: wrote %zu bytes, closing stdin\n", __func__, written);
645645
fclose(f);
646+
// subprocess_stdin() returns sp->stdin_file directly; fclosing our local
647+
// copy leaves the struct pointer dangling, so subprocess_destroy() would
648+
// fclose() the same FILE again -> heap corruption. Null it so the later
649+
// destroy skips stdin.
650+
sp->stdin_file = nullptr;
646651
}
647652

648653
bool probe(float fps_target_arg) {

0 commit comments

Comments
 (0)