From 005bfc694d167b7da4b565a1c4de03592fdbe86e Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 20 Sep 2012 22:51:47 -0700 Subject: [PATCH] Fix for native crash on image decode OOM When decoding an image with scaling, if the allocation of the bitmap data for the scaled bitmap failed, we were just ignoring it and going on. This was yielding strange native crashes (bug 7196860 and bug 7175536). This patch checks whether the allocation succeeds, and returns a null bitmap if not. Of course, if the app really is OOM because it's allocated too many bitmaps, it'll still get the OOME, but that's a lot nicer than a native crash or memory corruption. Change-Id: I8384059ab11c2ab9e93e283b9438d79e6709b7b1 --- core/jni/android/graphics/BitmapFactory.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index 69ef08099a5d0..88233286e68f0 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -340,7 +340,9 @@ static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding, bitmap->setConfig(config, scaledWidth, scaledHeight); bitmap->setIsOpaque(decoded->isOpaque()); - bitmap->allocPixels(&javaAllocator, NULL); + if (!bitmap->allocPixels(&javaAllocator, NULL)) { + return nullObjectReturn("allocation failed for scaled bitmap"); + } bitmap->eraseColor(0); SkPaint paint;