Skip to content

Commit

Permalink
Fix RCTImageBlurUtils.m Greyscale Crash (#37508)
Browse files Browse the repository at this point in the history
Summary:
## Summary:

This PR fixes a kernel crash caused by trying to blur greyscale images, as described in this issue:
#35706 (comment)

## Context:

The CGImageGetBitsPerPixel(imageRef) == 8 expression checks if each pixel of the image is represented by 8 bits.

In an image, each pixel is typically represented by a certain amount of information to store its color. In a grayscale image, for instance, we often use 8 bits per pixel, which allows for 256 different shades of gray (2^8 = 256).

The function vImageBoxConvolve_ARGB8888 works with ARGB images (which stands for Alpha, Red, Green, Blue). If the image is only black & white, it means it's a grayscale image, and hence, it is not compatible with this function, causing the kernel crash.

To prevent the issue, we should also convert grayscale images to ARGB before processing them.

## Changelog:
[IOS] [FIXED] - Fix RCTImageBlurUtils.m Greyscale Crash

Pull Request resolved: #37508

Test Plan:
```
<ImageBackground
        blurRadius={18}
        source={{uri: 'https://i.scdn.co/image/ab67616d0000b2737663b2f75fe4d8fb2cac8c27'}}
/>

<ImageBackground
        blurRadius={5}
        source={{uri: 'https://i.scdn.co/image/ab67616d0000b273d5a219b270d74a266131df18'}}
/>
``

Reviewed By: NickGerleman

Differential Revision: D46071330

Pulled By: javache

fbshipit-source-id: 8c04cbf88d467596c9c8a9de9a380bc10663a0e5
  • Loading branch information
OskarEichler authored and facebook-github-bot committed May 23, 2023
1 parent af6ef85 commit d6c4f27
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions packages/react-native/Libraries/Image/RCTImageBlurUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
}

// convert to ARGB if it isn't
if (CGImageGetBitsPerPixel(imageRef) != 32 || CGImageGetBitsPerComponent(imageRef) != 8 ||
!((CGImageGetBitmapInfo(imageRef) & kCGBitmapAlphaInfoMask))) {
if (CGImageGetBitsPerPixel(imageRef) != 32 || !((CGImageGetBitmapInfo(imageRef) & kCGBitmapAlphaInfoMask))) {
UIGraphicsImageRendererFormat *const rendererFormat = [UIGraphicsImageRendererFormat defaultFormat];
rendererFormat.scale = inputImage.scale;
UIGraphicsImageRenderer *const renderer = [[UIGraphicsImageRenderer alloc] initWithSize:inputImage.size
Expand Down

0 comments on commit d6c4f27

Please sign in to comment.