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

Commit d37095b7 authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Fix bitmap allocation error that causes crash when calling Bitmap::extractAlpha

bug: 19112656
Change-Id: Ib44ba4208449d5873402e9516abc8b6d8fa0b82a
parent 7ba4751e
Loading
Loading
Loading
Loading
+20 −15
Original line number Diff line number Diff line
@@ -511,17 +511,14 @@ AndroidPixelRef::~AndroidPixelRef() {

///////////////////////////////////////////////////////////////////////////////

static bool computeAllocationSize(const SkImageInfo& info, size_t* size, size_t* rowBytes) {
        int32_t rowBytes32 = SkToS32(info.minRowBytes());
        int64_t bigSize = (int64_t)info.height() * rowBytes32;
static bool computeAllocationSize(const SkBitmap& bitmap, size_t* size) {
    int32_t rowBytes32 = SkToS32(bitmap.rowBytes());
    int64_t bigSize = (int64_t)bitmap.height() * rowBytes32;
    if (rowBytes32 < 0 || !sk_64_isS32(bigSize)) {
        return false; // allocation will be too large
    }

    *size = sk_64_asS32(bigSize);
        *rowBytes = rowBytes32;

        SkASSERT(*size >= info.getSafeSize(*rowBytes));
    return true;
}

@@ -533,11 +530,15 @@ jbyteArray GraphicsJNI::allocateJavaPixelRef(JNIEnv* env, SkBitmap* bitmap,
        return NULL;
    }

    size_t size, rowBytes;
    if (!computeAllocationSize(info, &size, &rowBytes)) {
    size_t size;
    if (!computeAllocationSize(*bitmap, &size)) {
        return NULL;
    }

    // we must respect the rowBytes value already set on the bitmap instead of
    // attempting to compute our own.
    const size_t rowBytes = bitmap->rowBytes();

    jbyteArray arrayObj = (jbyteArray) env->CallObjectMethod(gVMRuntime,
                                                             gVMRuntime_newNonMovableArray,
                                                             gByte_class, size);
@@ -580,11 +581,15 @@ bool GraphicsJNI::allocatePixels(JNIEnv* env, SkBitmap* bitmap, SkColorTable* ct
        return NULL;
    }

    size_t size, rowBytes;
    if (!computeAllocationSize(info, &size, &rowBytes)) {
    size_t size;
    if (!computeAllocationSize(*bitmap, &size)) {
        return false;
    }

    // we must respect the rowBytes value already set on the bitmap instead of
    // attempting to compute our own.
    const size_t rowBytes = bitmap->rowBytes();

    void* addr = sk_malloc_flags(size, 0);
    if (NULL == addr) {
        return false;