Skip to content

Conversation

@Gounlaf
Copy link
Contributor

@Gounlaf Gounlaf commented Feb 8, 2024

👋

  • ImageMagick requires size_t for with & height, but allow 0.
  • no checks done on https://github.com/dlemstra/Magick.Native/blob/a01f5e641d52b1bbf2bf6f5795aba4b4c054a22d/src/Magick.Native/MagickImage.c#L700-L711
  • no checks done on binding, only casting
    public void AdaptiveThreshold(int width, int height, double bias, Channels channels)
    {
    IntPtr exception = IntPtr.Zero;
    IntPtr result;
    #if PLATFORM_AnyCPU
    if (Runtime.IsArm64)
    #endif
    #if PLATFORM_arm64 || PLATFORM_AnyCPU
    result = NativeMethods.ARM64.MagickImage_AdaptiveThreshold(Instance, (UIntPtr)width, (UIntPtr)height, bias, (NativeChannelsType)channels, out exception);
    #endif
    #if PLATFORM_AnyCPU
    else if (Runtime.Is64Bit)
    #endif
    #if PLATFORM_x64 || PLATFORM_AnyCPU
    result = NativeMethods.X64.MagickImage_AdaptiveThreshold(Instance, (UIntPtr)width, (UIntPtr)height, bias, (NativeChannelsType)channels, out exception);
    #endif
    #if PLATFORM_AnyCPU
    else
    #endif
    #if PLATFORM_x86 || PLATFORM_AnyCPU
    result = NativeMethods.X86.MagickImage_AdaptiveThreshold(Instance, (UIntPtr)width, (UIntPtr)height, bias, (NativeChannelsType)channels, out exception);
    #endif
    CheckException(exception, result);
    if (result != IntPtr.Zero)
    Instance = result;
    }

Regards.

Copy link
Owner

@dlemstra dlemstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help.

@dlemstra dlemstra merged commit 258d230 into dlemstra:main Feb 8, 2024
@Gounlaf Gounlaf deleted the magickimage-adaptivethreshold-guards branch February 9, 2024 15:02
This was referenced Jul 23, 2025
This was referenced Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants