From a1f68dbfb4bf63356b89f7c21aae3d03ae9570bd Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Fri, 31 May 2024 12:06:33 -0700 Subject: [PATCH] Avoid returning mutable Path in CSSBackgroundDrawable (#44733) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44733 We are returning a Path to callers, which shouldn't be mutated. This isn't really safe. Return a copy to external callers instead, if they need a path to work with. Changelog: [Internal] Reviewed By: rshest Differential Revision: D57996157 fbshipit-source-id: 53cd95df6e2641d946f7c3fef40f6449b16ca5cb --- .../react/uimanager/drawable/CSSBackgroundDrawable.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/CSSBackgroundDrawable.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/CSSBackgroundDrawable.java index 0706cf9b45d..fc2cd0c5d0f 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/CSSBackgroundDrawable.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/CSSBackgroundDrawable.java @@ -319,7 +319,7 @@ public class CSSBackgroundDrawable extends Drawable { public @Nullable Path getBorderBoxPath() { if (hasRoundedBorders()) { updatePath(); - return Preconditions.checkNotNull(mOuterClipPathForBorderRadius); + return new Path(Preconditions.checkNotNull(mOuterClipPathForBorderRadius)); } return null; @@ -332,7 +332,7 @@ public class CSSBackgroundDrawable extends Drawable { public @Nullable Path getPaddingBoxPath() { if (hasRoundedBorders()) { updatePath(); - return Preconditions.checkNotNull(mInnerClipPathForBorderRadius); + return new Path(Preconditions.checkNotNull(mInnerClipPathForBorderRadius)); } return null; @@ -356,7 +356,7 @@ public class CSSBackgroundDrawable extends Drawable { canvas.save(); // Clip outer border - canvas.clipPath(Preconditions.checkNotNull(getBorderBoxPath()), Region.Op.INTERSECT); + canvas.clipPath(Preconditions.checkNotNull(mOuterClipPathForBorderRadius), Region.Op.INTERSECT); // Draws the View without its border first (with background color fill) int useColor = ColorUtils.setAlphaComponent(mColor, getOpacity()); @@ -415,7 +415,8 @@ public class CSSBackgroundDrawable extends Drawable { mPaint.setStyle(Paint.Style.FILL); // Clip inner border - canvas.clipPath(Preconditions.checkNotNull(getPaddingBoxPath()), Region.Op.DIFFERENCE); + canvas.clipPath( + Preconditions.checkNotNull(mInnerClipPathForBorderRadius), Region.Op.DIFFERENCE); final boolean isRTL = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; int colorStart = getBorderColor(Spacing.START);