summaryrefslogtreecommitdiffstats
path: root/video/image_writer.h
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/image_writer.h
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/image_writer.h')
-rw-r--r--video/image_writer.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/video/image_writer.h b/video/image_writer.h
index 72d160269b..c22606ed65 100644
--- a/video/image_writer.h
+++ b/video/image_writer.h
@@ -68,7 +68,7 @@ int image_writer_format_from_ext(const char *ext);
*/
bool write_image(struct mp_image *image, const struct image_writer_opts *opts,
const char *filename, struct mpv_global *global,
- struct mp_log *log);
+ struct mp_log *log, bool overwrite);
// Debugging helper.
void dump_png(struct mp_image *image, const char *filename, struct mp_log *log);