From 808a685f3c538621d5dfecd9928d2f75a4b7f68e Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Fri, 29 Oct 2021 13:38:52 -0700 Subject: [PATCH] Hardcode the maximum FD size for honor/huawei devices to avoid native crashes. Fixes #4165 PiperOrigin-RevId: 406440064 --- .../ParcelFileDescriptorBitmapDecoder.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ParcelFileDescriptorBitmapDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ParcelFileDescriptorBitmapDecoder.java index b92fa1983d..c155e9bd24 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ParcelFileDescriptorBitmapDecoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ParcelFileDescriptorBitmapDecoder.java @@ -16,6 +16,12 @@ public final class ParcelFileDescriptorBitmapDecoder implements ResourceDecoder { + // 512MB. While I don't have data on the number of valid image files > 512mb, I have determined + // that virtually all crashes related to Huawei/Honor's DRM checker go away when we don't attempt + // to decode files larger than this. We could increase this to 1GB safely, but it seems like 512MB + // might be a little better from a crash reduction perspective. See b/201464175. + private static final int MAXIMUM_FILE_BYTE_SIZE_FOR_FILE_DESCRIPTOR_DECODER = 512 * 1024 * 1024; + private final Downsampler downsampler; public ParcelFileDescriptorBitmapDecoder(Downsampler downsampler) { @@ -24,7 +30,15 @@ public ParcelFileDescriptorBitmapDecoder(Downsampler downsampler) { @Override public boolean handles(@NonNull ParcelFileDescriptor source, @NonNull Options options) { - return downsampler.handles(source); + return isSafeToTryDecoding(source) && downsampler.handles(source); + } + + private boolean isSafeToTryDecoding(@NonNull ParcelFileDescriptor source) { + if ("HUAWEI".equalsIgnoreCase(Build.MANUFACTURER) + || "HONOR".equalsIgnoreCase(Build.MANUFACTURER)) { + return source.getStatSize() <= MAXIMUM_FILE_BYTE_SIZE_FOR_FILE_DESCRIPTOR_DECODER; + } + return true; } @Nullable