Skip to content

Commit

Permalink
Fix ResourceID validation check expression
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hyuns66 committed Sep 9, 2024
1 parent a7351b0 commit dc8fb9d
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Expand All @@ -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());
}
}
Expand All @@ -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 =
Expand Down

0 comments on commit dc8fb9d

Please sign in to comment.