Browse files

Fix crash with non-zero blurRadius less than 1

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 dc01eff72d23e1dd3f7ecf30859992ee3bf7c664
Showing with 3 additions and 3 deletions.
  1. +3 −3 ReactAndroid/src/main/java/com/facebook/react/views/image/
@@ -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;

0 comments on commit dc01eff

Please sign in to comment.