Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading a video file leaves behind a temporary file on Windows #7389

Closed
reima opened this issue Jun 10, 2024 · 2 comments
Closed

Reading a video file leaves behind a temporary file on Windows #7389

reima opened this issue Jun 10, 2024 · 2 comments

Comments

@reima
Copy link

reima commented Jun 10, 2024

ImageMagick version

7.1.1-33

Operating system

Windows

Operating system, version and so on

Windows 11 23H2

Description

Reading a video file via the C or C API of ImageMagick on Windows will leave behind a copy of the file in the temporary directory.

I've identified that two temporary files are created in ReadVIDEOImage:

ImageMagick/coders/video.c

Lines 253 to 255 in 05a551a

AcquireUniqueFilename(read_info->unique);
(void) AcquireUniqueSymbolicLink(image_info->filename,
read_info->filename);

read_info->unique is used as the output file path for the delegate. read_info->filename is used as the input file path for the delegate. Note that AcquireUniqueSymbolicLink creates a copy of the file when running on Windows.

After building the delegate command line, read_info->filename is overwritten with the content of read_info->unique:

ImageMagick/coders/video.c

Lines 262 to 263 in 05a551a

(void) CopyMagickString(read_info->filename,read_info->unique,
MagickPathExtent);

The two temporary files should in theory be removed in these lines:

ImageMagick/coders/video.c

Lines 272 to 273 in 05a551a

(void) RelinquishUniqueFileResource(read_info->filename);
(void) RelinquishUniqueFileResource(read_info->unique);

But as read_info->filename has already been overwritten, this will not remove the temporary file.

Note that MagickCoreTerminus will delete this temporary file. This is why the problem is not directly observable with the ImageMagick command line tools.

Steps to Reproduce

The following trivial Magick program reproduces the problem:

#include <Magick  .h>
#include <iostream>

int main(int argc, char **argv)
{
    Magick::InitializeMagick(*argv);

    try
    {
        Magick::Image image;
        image.read("F:\\test.mp4[0]"); // any file that ImageMagick identifies as video will do
    }
    catch (Magick::Exception& error)
    {
        std::cout << "Error: " << error.what() << std::endl;
    }

    // Temporary file still exists.

    Magick::TerminateMagick();

    // Temporary file has been deleted.
}

Images

No response

dlemstra added a commit that referenced this issue Jun 10, 2024
@dlemstra
Copy link
Member

Thanks for reporting this and the detailed information. I just pushed a patch to make sure this will be fixed in the next release.

@reima
Copy link
Author

reima commented Jun 11, 2024

I can confirm that the issue is fixed on the main branch.

As always, thank you very much for the swift response! I really appreciate it.

@reima reima closed this as completed Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants