Fix crash with non-zero blurRadius less than 1

Summary:
There's a crash-inducing bug with `Image.blurRadius` on Android.

`blurRadius` is specified in JavaScript as a `float`, but it's cast to `int` before being passed to the `IterativeBoxBlurPostProcessor`. However, in `IterativeBoxBlurPostProcessor`, there is an argument precondition requiring the integer `blurRadius` to be non-zero.

Because the `== 0` condition is evaluated on the `float`, it's possible for a `blurRadius` in the range of `(0, 1)` (non-inclusive) to pass the conditional, and then be truncated to `0` and passed as an argument to `IterativeBoxBlurPostProcessor`, which will fail its precondition and crash the app.

This change works in our app, which was previously crashing.

[ANDROID] [BUGFIX] [Image] Fixed crash when specifying an Image.blurRadius between (0, 1)
Closes https://github.com/facebook/react-native/pull/16845

Differential Revision: D6387416

Pulled By: shergin

fbshipit-source-id: d5191aa97e949ffd41e6d68c96b3c7bcbc82a52e
This commit is contained in:
James Reggio 2017-11-21 12:08:44 -08:00 committed by Facebook Github Bot
parent b9a5862f67
commit dc01eff72d
1 changed files with 3 additions and 3 deletions

View File

@ -229,11 +229,11 @@ public class ReactImageView extends GenericDraweeView {
}
public void setBlurRadius(float blurRadius) {
if (blurRadius == 0) {
int pixelBlurRadius = (int) PixelUtil.toPixelFromDIP(blurRadius);
if (pixelBlurRadius == 0) {
mIterativeBoxBlurPostProcessor = null;
} else {
mIterativeBoxBlurPostProcessor =
new IterativeBoxBlurPostProcessor((int) PixelUtil.toPixelFromDIP(blurRadius));
mIterativeBoxBlurPostProcessor = new IterativeBoxBlurPostProcessor(pixelBlurRadius);
}
mIsDirty = true;
}