diff options
author | nanahi <130121847+na-na-hi@users.noreply.github.com> | 2024-03-19 00:38:58 -0400 |
---|---|---|
committer | Kacper Michajłow <kasper93@gmail.com> | 2024-03-19 19:30:27 +0100 |
commit | 9a861c930bac32ee3febedc0b0653be4f6f66fef (patch) | |
tree | bc870607001bab657dc30885a6dd837902d89a66 /test | |
parent | aa08e304c46dd25daa50a097fc8bbf74be13fc86 (diff) | |
download | mpv-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 'test')
-rw-r--r-- | test/scale_test.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/test/scale_test.c b/test/scale_test.c index fa7886de48..8d8f63f0ee 100644 --- a/test/scale_test.c +++ b/test/scale_test.c @@ -60,7 +60,7 @@ static void dump_image(struct scale_test *stest, const char *name, struct image_writer_opts opts = image_writer_opts_defaults; opts.format = AV_CODEC_ID_PNG; - if (!write_image(img, &opts, path, NULL, NULL)) { + if (!write_image(img, &opts, path, NULL, NULL, true)) { printf("Failed to write '%s'.\n", path); abort(); } |