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

fix: add guards for MagickImage.AdaptiveThreshold #1544

Merged

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
25 checks passed
@Gounlaf Gounlaf deleted the magickimage-adaptivethreshold-guards branch February 9, 2024 15:02
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