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

Long file path : STATUS_HEAP_CORRUPTION #453

Closed
fire-eggs opened this issue Jun 1, 2019 · 2 comments
Closed

Long file path : STATUS_HEAP_CORRUPTION #453

fire-eggs opened this issue Jun 1, 2019 · 2 comments

Comments

@fire-eggs
Copy link

Description

I've run into an issue when using long file paths (a path longer than 260 chars). The symptom suggests an issue with ImageMagick, but thought I'd start here.

Using new MagickImage(filename, settings) to open an image, if filename is a long path name, we will get a STATUS_HEAP_CORRUPTION error. On 64-bit processes, this is an immediate process shutdown (cannot be caught).

This is a minor issue for our project, as it can be worked around (by using File.ReadAllBytes and passing the byte array to ImageMagick).

Interestingly, if the path provided points to a file which doesn't exist, there is no issue. So the issue occurs in the "success" code path.

Steps to Reproduce

           // filename is a path to an image, path is > 260 characters long
            var settings = new MagickReadSettings();
                        using (var imgM = new MagickImage(filename, settings))
                        {
                            Bitmap bitmap = imgM.ToBitmap();
                        }

System Configuration

Windows 10, builds 1803, 1809.
The behavior is not impacted by the "Enable Win32 long paths" setting.
.NET Framework 4.7.1

  • Magick.NET version: Q16-AnyCPU: 7.12.0.0; 7.13.1
@dlemstra dlemstra added this to the 7.13.2.0 milestone Jun 2, 2019
@dlemstra
Copy link
Owner

dlemstra commented Jun 2, 2019

Thank you for finding this bug! ImageMagick calls GetShortPathNameW to get the 8.3 alias for the specified path. But it appears that it is possible that the 8.3 alias does not exist. I just pushed some patches to the ImageMagick repository to add some extra checks for this. And I have also added a check to test if HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled (https://docs.microsoft.com/nl-nl/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation) is set to true and don't call GetShortPathNameW then. This issue will be resolved in the next release of Magick.NET.

@fire-eggs
Copy link
Author

I'm glad it was helpful! Keep up the good work!

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

No branches or pull requests

2 participants