Skip to content

mtmd: fix double-close of ffmpeg/ffprobe stdin in video helper#24313

Closed
mudler wants to merge 1 commit into
ggml-org:masterfrom
mudler:fix/mtmd-video-stdin-double-close
Closed

mtmd: fix double-close of ffmpeg/ffprobe stdin in video helper#24313
mudler wants to merge 1 commit into
ggml-org:masterfrom
mudler:fix/mtmd-video-stdin-double-close

Conversation

@mudler

@mudler mudler commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Overview

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 path is unaffected because it never spawns the stdin feeder.

Clear sp->stdin_file after fclose() so subprocess_destroy() skips it.

cc @ngxson

Requirements

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>
Comment on lines +646 to +649
// subprocess_stdin() returns sp->stdin_file directly; fclosing our local
// copy leaves the struct pointer dangling, so subprocess_destroy() would
// fclose() the same FILE again -> heap corruption. Null it so the later
// destroy skips stdin.

This comment was marked as outdated.

@ngxson

ngxson commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

thanks for reporting the issue, however I decided to refactor the subprocess handling in #24316 (which makes it conflicts with this PR)

could you check if it fixes the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants