Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ private enum OnVisibleAction {
"reducedmotion"
);

/**
* Significantly larger than the largest expected size, equivalent to about 1.5x an 8K display.
*/
private static final long MAX_SOFTWARE_BITMAP_PIXELS = 50_000_000L;

private LottieComposition composition;
private final LottieValueAnimator animator = new LottieValueAnimator();

Expand Down Expand Up @@ -1795,10 +1800,22 @@ private void renderAndDrawAsBitmap(Canvas originalCanvas, CompositionLayer compo
softwareRenderingTransformedBounds.intersect(canvasClipBounds.left, canvasClipBounds.top, canvasClipBounds.right, canvasClipBounds.bottom);
}

if (!isFiniteRect(softwareRenderingTransformedBounds)) {
Logger.warning("Skipping software rendering: transformed bounds contain non-finite values.");
return;
}

int renderWidth = (int) Math.ceil(softwareRenderingTransformedBounds.width());
int renderHeight = (int) Math.ceil(softwareRenderingTransformedBounds.height());

if (renderWidth <= 0 || renderHeight <= 0) {
Logger.warning("Skipping software rendering: transformed bounds have negative values.");
return;
}

long renderPixelCount = (long) renderWidth * (long) renderHeight;
if (renderPixelCount > MAX_SOFTWARE_BITMAP_PIXELS) {
Logger.warning("Skipping software rendering: bitmap request exceeds safe pixel count (" + renderPixelCount + ")");
return;
}

Expand Down Expand Up @@ -1890,6 +1907,17 @@ private void convertRect(Rect src, RectF dst) {
src.bottom);
}

private static boolean isFiniteRect(RectF rect) {
return isFinite(rect.left) &&
isFinite(rect.top) &&
isFinite(rect.right) &&
isFinite(rect.bottom);
}

private static boolean isFinite(float value) {
return !Float.isNaN(value) && !Float.isInfinite(value);
}

private void scaleRect(RectF rect, float scaleX, float scaleY) {
rect.set(
rect.left * scaleX,
Expand Down
Loading