Skip to content

There are buffer overruns bugs around NativeMemory.Alloc usage #1

@smourier

Description

@smourier

NativeMemory.Alloc allocates a byte count so you should pass half the buffer's size to Shell APIs which are expecting unicode-sized buffers.

Typically, this crashes on my PC:

    public static byte[]? GetThumbnail(IShellLinkW* pShellLink, int size = 32)
    {
            ...
            pwszIconLocation = (char*)NativeMemory.Alloc(256);
            hr = pShellLink->GetIconLocation(pwszIconLocation, 256, &nIconIndex);
            ...

It should be

            hr = pShellLink->GetIconLocation(pwszIconLocation, 128, &nIconIndex);

And in fact IMHO, you should pass bigger buffers to avoid truncation, at least 512 but it can be more (not everything is under the MAX_PATH rule, Microsoft is very unclear about this).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions