From ef7be262e5859efdf805d1b9612bc2b250d5971e Mon Sep 17 00:00:00 2001 From: Eric Hassold Date: Wed, 23 Feb 2011 16:46:11 -0800 Subject: [PATCH] Detect out of memory in extractAlpha When extractAlpha() native method in Skia fails to allocate pixels, it resets target bitmap. This change detects when such empty bitmap is returned, and throws a OutOfMemory Java exception. Depends on https://android-git.corp.google.com/g/97793 Bug: 3418381 Change-Id: I65a84998be089c49ed5005f6995bdc4f4d1669bc --- core/jni/android/graphics/Bitmap.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp index 1d961ec935997..9b7c83c5e3860 100644 --- a/core/jni/android/graphics/Bitmap.cpp +++ b/core/jni/android/graphics/Bitmap.cpp @@ -447,6 +447,13 @@ static jobject Bitmap_extractAlpha(JNIEnv* env, jobject clazz, JavaPixelAllocator allocator(env); src->extractAlpha(dst, paint, &allocator, &offset); + // If Skia can't allocate pixels for destination bitmap, it resets + // it, that is set its pixels buffer to NULL, and zero width and height. + if (dst->getPixels() == NULL && src->getPixels() != NULL) { + delete dst; + doThrowOOME(env, "failed to allocate pixels for alpha"); + return NULL; + } if (offsetXY != 0 && env->GetArrayLength(offsetXY) >= 2) { int* array = env->GetIntArrayElements(offsetXY, NULL); array[0] = offset.fX; @@ -651,4 +658,3 @@ int register_android_graphics_Bitmap(JNIEnv* env) return android::AndroidRuntime::registerNativeMethods(env, kClassPathName, gBitmapMethods, SK_ARRAY_COUNT(gBitmapMethods)); } -