Skip to content

Commit dc8fb9d

Browse files
committed
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.
1 parent a7351b0 commit dc8fb9d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

library/src/main/java/com/bumptech/glide/request/SingleRequest.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import android.content.res.Resources.Theme;
55
import android.graphics.drawable.Drawable;
66
import android.util.Log;
7+
8+
import androidx.annotation.AnyRes;
79
import androidx.annotation.DrawableRes;
810
import androidx.annotation.GuardedBy;
911
import androidx.annotation.NonNull;
@@ -387,7 +389,7 @@ public boolean isAnyResourceSet() {
387389
private Drawable getErrorDrawable() {
388390
if (errorDrawable == null) {
389391
errorDrawable = requestOptions.getErrorPlaceholder();
390-
if (errorDrawable == null && requestOptions.getErrorId() > 0) {
392+
if (errorDrawable == null && isValidId(requestOptions.getErrorId())) {
391393
errorDrawable = loadDrawable(requestOptions.getErrorId());
392394
}
393395
}
@@ -398,7 +400,7 @@ private Drawable getErrorDrawable() {
398400
private Drawable getPlaceholderDrawable() {
399401
if (placeholderDrawable == null) {
400402
placeholderDrawable = requestOptions.getPlaceholderDrawable();
401-
if (placeholderDrawable == null && requestOptions.getPlaceholderId() > 0) {
403+
if (placeholderDrawable == null && isValidId(requestOptions.getPlaceholderId())) {
402404
placeholderDrawable = loadDrawable(requestOptions.getPlaceholderId());
403405
}
404406
}
@@ -409,13 +411,20 @@ private Drawable getPlaceholderDrawable() {
409411
private Drawable getFallbackDrawable() {
410412
if (fallbackDrawable == null) {
411413
fallbackDrawable = requestOptions.getFallbackDrawable();
412-
if (fallbackDrawable == null && requestOptions.getFallbackId() > 0) {
414+
if (fallbackDrawable == null && isValidId(requestOptions.getFallbackId())) {
413415
fallbackDrawable = loadDrawable(requestOptions.getFallbackId());
414416
}
415417
}
416418
return fallbackDrawable;
417419
}
418420

421+
/**
422+
* @see android.content.res.ResourceId.isValid
423+
*/
424+
private static boolean isValidId(int id) {
425+
return id != -1 && (id & 0xff000000) != 0 && (id & 0x00ff0000) != 0;
426+
}
427+
419428
@GuardedBy("requestLock")
420429
private Drawable loadDrawable(@DrawableRes int resourceId) {
421430
Theme theme =

0 commit comments

Comments
 (0)