commit | d555fc4025cd2a6e3cb010a38def27d178850464 | [log] [tgz] |
---|---|---|
author | Allen Chen <allenchen1154@gmail.com> | Wed Sep 24 17:52:31 2025 -0500 |
committer | Allen Chen <allenchen1154@gmail.com> | Wed Sep 24 17:52:31 2025 -0500 |
tree | 92923d81c4f3ef473575e98bf3dc7b6144ceaff7 | |
parent | 5af8c292990374c28468b9a14080242f165d4c8c [diff] |
Safeguard against very large Bitmap creation Because we rely on the transform `Matrix` returned from the `Canvas` to size a `Bitmap` when using software rendering, an erroneous matrix value can cause a very large Bitmap to be allocated, triggering an OutOfMemory exception. We've encountered such a situation when using `layoutlib` for screenshot tests, which uses a `NopCanvas` [on initial render](https://cs.android.com/android/_/android/platform/frameworks/layoutlib/+/7b05b277beee599532606e9bb6d7a71f5ca2ab6e:bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java;l=543;bpv=1;bpt=0;drc=085857f145aac790e2a08cf6eb9546f98e26c338) that can return an invalid `Matrix.
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java index 9c2f424..69eb1a3 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
@@ -1798,7 +1798,8 @@ int renderWidth = (int) Math.ceil(softwareRenderingTransformedBounds.width()); int renderHeight = (int) Math.ceil(softwareRenderingTransformedBounds.height()); - if (renderWidth <= 0 || renderHeight <= 0) { + // Safeguard against errors during Bitmap creation by returning early if dimensions are invalid. + if (renderWidth <= 0 || renderHeight <= 0 || renderWidth > bounds.width() || renderHeight > bounds.height()) { return; }