From 03738d58595e0d62f0b9f8815a27cc7eb52d1c2a Mon Sep 17 00:00:00 2001 From: James Zern Date: Tue, 19 Nov 2024 18:06:47 -0800 Subject: [PATCH] libavif_jni: add missing error check (#2508) `image_copy` is reset with the result of `avifImageCreateEmpty()` which can fail. This change adds a check to match the one used for `cropped_image`. --- android_jni/avifandroidjni/src/main/jni/libavif_jni.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android_jni/avifandroidjni/src/main/jni/libavif_jni.cc b/android_jni/avifandroidjni/src/main/jni/libavif_jni.cc index fe4bfe3314..66f6e902dd 100644 --- a/android_jni/avifandroidjni/src/main/jni/libavif_jni.cc +++ b/android_jni/avifandroidjni/src/main/jni/libavif_jni.cc @@ -149,6 +149,10 @@ avifResult AvifImageToBitmap(JNIEnv* const env, // scaling. if (!image->imageOwnsYUVPlanes || !image->imageOwnsAlphaPlane) { image_copy.reset(avifImageCreateEmpty()); + if (image_copy == nullptr) { + LOGE("Failed to allocate image for scaling."); + return AVIF_RESULT_OUT_OF_MEMORY; + } res = avifImageCopy(image_copy.get(), image, AVIF_PLANES_ALL); if (res != AVIF_RESULT_OK) { LOGE("Failed to make a copy of the image for scaling. Status: %d", res);