Skip to content

Commit 005bfc6

Browse files
committed
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
1 parent 314488b commit 005bfc6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

core/jni/android/graphics/BitmapFactory.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,9 @@ static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding,
340340

341341
bitmap->setConfig(config, scaledWidth, scaledHeight);
342342
bitmap->setIsOpaque(decoded->isOpaque());
343-
bitmap->allocPixels(&javaAllocator, NULL);
343+
if (!bitmap->allocPixels(&javaAllocator, NULL)) {
344+
return nullObjectReturn("allocation failed for scaled bitmap");
345+
}
344346
bitmap->eraseColor(0);
345347

346348
SkPaint paint;

0 commit comments

Comments
 (0)