Skip to content

Commit ec1e960

Browse files
Guard against Bitmap allocations of size 0 (#2626)
Fixes #2620, which only occurs on Android 12 devices.
1 parent ccff9af commit ec1e960

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lottie/src/main/java/com/airbnb/lottie/utils/OffscreenLayer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ private Bitmap allocateBitmap(RectF bounds, Bitmap.Config cfg) {
186186
// still being relatively speedy to blit and operate on.
187187
int width = (int)Math.ceil(bounds.width() * 1.05);
188188
int height = (int)Math.ceil(bounds.height() * 1.05);
189-
return Bitmap.createBitmap(width, height, cfg);
189+
190+
// In certain cases the provided bounds can have a width or height of 0, which will cause a runtime crash
191+
// when we try to allocate a Bitmap. To guard against this, use a minimum size of 1x1.
192+
// See https://github.com/airbnb/lottie-android/issues/2620
193+
return Bitmap.createBitmap(Math.max(width, 1), Math.max(height, 1), cfg);
190194
}
191195

192196
private void deallocateBitmap(Bitmap bitmap) {

0 commit comments

Comments
 (0)