summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authornanahi <130121847+na-na-hi@users.noreply.github.com>2024-03-19 00:38:58 -0400
committerKacper Michajłow <kasper93@gmail.com>2024-03-19 19:30:27 +0100
commit9a861c930bac32ee3febedc0b0653be4f6f66fef (patch)
treebc870607001bab657dc30885a6dd837902d89a66 /video/out
parentaa08e304c46dd25daa50a097fc8bbf74be13fc86 (diff)
downloadmpv-9a861c930bac32ee3febedc0b0653be4f6f66fef.tar.bz2
mpv-9a861c930bac32ee3febedc0b0653be4f6f66fef.tar.xz
image_writer: fix TOCTOU in screenshot filename generation
The screenshot command is documented to not overwrite existing files. However, there is a race window between the filename is generated with gen_fname and when the file is open to write. Specifically, the convert_image function in this window can be very time consuming depending on video and screenshot image format and size. This results in existing file being overwritten because the file writing functions don't check for the existance of file. Fix this be opening the file in exclusive mode. Add overwrite parameter to write_image for other operations that are documented to overwrite existing files, like screenshot-to-file. Note that for write_avif, checking existance is used instead because avio_open does not support exclusive open mode.
Diffstat (limited to 'video/out')
-rw-r--r--video/out/vo_image.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/video/out/vo_image.c b/video/out/vo_image.c
index cc48ab3404..84e164f6e5 100644
--- a/video/out/vo_image.c
+++ b/video/out/vo_image.c
@@ -118,7 +118,7 @@ static void flip_page(struct vo *vo)
filename = mp_path_join(t, p->opts->outdir, filename);
MP_INFO(vo, "Saving %s\n", filename);
- write_image(p->current, p->opts->opts, filename, vo->global, vo->log);
+ write_image(p->current, p->opts->opts, filename, vo->global, vo->log, true);
talloc_free(t);
}