Skip to content

Commit

Permalink
Fix crash with non-zero blurRadius less than 1
Browse files Browse the repository at this point in the history
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 #16845

Differential Revision: D6387416

Pulled By: shergin

fbshipit-source-id: d5191aa97e949ffd41e6d68c96b3c7bcbc82a52e
  • Loading branch information
jamesreggio authored and facebook-github-bot committed Nov 21, 2017
1 parent b9a5862 commit dc01eff
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ public void onFailure(String id, Throwable throwable) {
}

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;
}
Expand Down

0 comments on commit dc01eff

Please sign in to comment.