Skip to content

Commit

Permalink
Hardcode the maximum FD size for honor/huawei devices to avoid native…
Browse files Browse the repository at this point in the history
… crashes.

Fixes #4165

PiperOrigin-RevId: 406440064
  • Loading branch information
sjudd authored and glide-copybara-robot committed Oct 29, 2021
1 parent 833ef21 commit 808a685
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
public final class ParcelFileDescriptorBitmapDecoder
implements ResourceDecoder<ParcelFileDescriptor, Bitmap> {

// 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) {
Expand All @@ -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
Expand Down

0 comments on commit 808a685

Please sign in to comment.