summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2021-04-22 16:55:09 -0400
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-08-12 08:04:53 +0000
commit6368d4cc9e759b5c5fa54148a03c4be313908d8d (patch)
treef23c1c1d35cc1ca8de04e790163fb97937b5413a
parent927dc5f7b6828ee271ca8bdd2a4113a8f63d983f (diff)
downloadbase-6368d4cc9e759b5c5fa54148a03c4be313908d8d.tar.gz
Fix a potential thread safety issue in VectorDrawable
Bug: 158839504 Bug: 185178568 Test: speculative Change-Id: Id9f229f08fe5897dda25441fbaa15c98f8130de9 (cherry picked from commit 6edabc03017fdaa60e99e47fb0da2c297949b671)
-rw-r--r--graphics/java/android/graphics/drawable/VectorDrawable.java10
1 files changed, 7 insertions, 3 deletions
diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java
index c71585f32155..8902a79b1bb7 100644
--- a/graphics/java/android/graphics/drawable/VectorDrawable.java
+++ b/graphics/java/android/graphics/drawable/VectorDrawable.java
@@ -342,15 +342,19 @@ public class VectorDrawable extends Drawable {
private final Rect mTmpBounds = new Rect();
public VectorDrawable() {
- this(new VectorDrawableState(null), null);
+ this(null, null);
}
/**
* The one constructor to rule them all. This is called by all public
* constructors to set the state and initialize local properties.
*/
- private VectorDrawable(@NonNull VectorDrawableState state, @Nullable Resources res) {
- mVectorState = state;
+ private VectorDrawable(@Nullable VectorDrawableState state, @Nullable Resources res) {
+ // As the mutable, not-thread-safe native instance is stored in VectorDrawableState, we
+ // need to always do a defensive copy even if mutate() isn't called. Otherwise
+ // draw() being called on 2 different VectorDrawable instances could still hit the same
+ // underlying native object.
+ mVectorState = new VectorDrawableState(state);
updateLocalState(res);
}