Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef7be262 authored by Eric Hassold's avatar Eric Hassold
Browse files

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
parent b7508df1
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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));
}