Skip to content

Commit 808a685

Browse files
sjuddglide-copybara-robot
authored andcommittedOct 29, 2021
Hardcode the maximum FD size for honor/huawei devices to avoid native crashes.
Fixes #4165 PiperOrigin-RevId: 406440064
1 parent 833ef21 commit 808a685

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed
 

‎library/src/main/java/com/bumptech/glide/load/resource/bitmap/ParcelFileDescriptorBitmapDecoder.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
public final class ParcelFileDescriptorBitmapDecoder
1717
implements ResourceDecoder<ParcelFileDescriptor, Bitmap> {
1818

19+
// 512MB. While I don't have data on the number of valid image files > 512mb, I have determined
20+
// that virtually all crashes related to Huawei/Honor's DRM checker go away when we don't attempt
21+
// to decode files larger than this. We could increase this to 1GB safely, but it seems like 512MB
22+
// might be a little better from a crash reduction perspective. See b/201464175.
23+
private static final int MAXIMUM_FILE_BYTE_SIZE_FOR_FILE_DESCRIPTOR_DECODER = 512 * 1024 * 1024;
24+
1925
private final Downsampler downsampler;
2026

2127
public ParcelFileDescriptorBitmapDecoder(Downsampler downsampler) {
@@ -24,7 +30,15 @@ public ParcelFileDescriptorBitmapDecoder(Downsampler downsampler) {
2430

2531
@Override
2632
public boolean handles(@NonNull ParcelFileDescriptor source, @NonNull Options options) {
27-
return downsampler.handles(source);
33+
return isSafeToTryDecoding(source) && downsampler.handles(source);
34+
}
35+
36+
private boolean isSafeToTryDecoding(@NonNull ParcelFileDescriptor source) {
37+
if ("HUAWEI".equalsIgnoreCase(Build.MANUFACTURER)
38+
|| "HONOR".equalsIgnoreCase(Build.MANUFACTURER)) {
39+
return source.getStatSize() <= MAXIMUM_FILE_BYTE_SIZE_FOR_FILE_DESCRIPTOR_DECODER;
40+
}
41+
return true;
2842
}
2943

3044
@Nullable

0 commit comments

Comments
 (0)
Please sign in to comment.