From dc8fb9d59983403c032bb9b6b615a9efcfe454de Mon Sep 17 00:00:00 2001 From: Hyuns66 Date: Mon, 9 Sep 2024 19:09:07 +0900 Subject: [PATCH] Fix ResourceID validation check expression there are three methods which have wrong expression getFallbackDrawable() getErrorDrawable()t getPlaceholderDrawable() According to the official documentation, resourceID can have a negative value, so I modified the if statement logic to include correct validation. --- .../com/bumptech/glide/request/SingleRequest.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/bumptech/glide/request/SingleRequest.java b/library/src/main/java/com/bumptech/glide/request/SingleRequest.java index 211936b20e..c95f61a123 100644 --- a/library/src/main/java/com/bumptech/glide/request/SingleRequest.java +++ b/library/src/main/java/com/bumptech/glide/request/SingleRequest.java @@ -4,6 +4,8 @@ import android.content.res.Resources.Theme; import android.graphics.drawable.Drawable; import android.util.Log; + +import androidx.annotation.AnyRes; import androidx.annotation.DrawableRes; import androidx.annotation.GuardedBy; import androidx.annotation.NonNull; @@ -387,7 +389,7 @@ public boolean isAnyResourceSet() { private Drawable getErrorDrawable() { if (errorDrawable == null) { errorDrawable = requestOptions.getErrorPlaceholder(); - if (errorDrawable == null && requestOptions.getErrorId() > 0) { + if (errorDrawable == null && isValidId(requestOptions.getErrorId())) { errorDrawable = loadDrawable(requestOptions.getErrorId()); } } @@ -398,7 +400,7 @@ private Drawable getErrorDrawable() { private Drawable getPlaceholderDrawable() { if (placeholderDrawable == null) { placeholderDrawable = requestOptions.getPlaceholderDrawable(); - if (placeholderDrawable == null && requestOptions.getPlaceholderId() > 0) { + if (placeholderDrawable == null && isValidId(requestOptions.getPlaceholderId())) { placeholderDrawable = loadDrawable(requestOptions.getPlaceholderId()); } } @@ -409,13 +411,20 @@ private Drawable getPlaceholderDrawable() { private Drawable getFallbackDrawable() { if (fallbackDrawable == null) { fallbackDrawable = requestOptions.getFallbackDrawable(); - if (fallbackDrawable == null && requestOptions.getFallbackId() > 0) { + if (fallbackDrawable == null && isValidId(requestOptions.getFallbackId())) { fallbackDrawable = loadDrawable(requestOptions.getFallbackId()); } } return fallbackDrawable; } + /** + * @see android.content.res.ResourceId.isValid + */ + private static boolean isValidId(int id) { + return id != -1 && (id & 0xff000000) != 0 && (id & 0x00ff0000) != 0; + } + @GuardedBy("requestLock") private Drawable loadDrawable(@DrawableRes int resourceId) { Theme theme =