From 7ab249a18e08bfefb8c2d60af1fb668c67ba4368 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Tue, 6 Jan 2015 18:17:52 +0000 Subject: Check for OOM in BitmapFactory's getMimeTypeString(). Bug: 18909596 Change-Id: If65fe45f5fd569a99a0cae1d31117af262bca430 --- core/jni/android/graphics/BitmapFactory.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'core/jni') diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index 0a95b44..592559a 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -63,7 +63,7 @@ jstring getMimeTypeString(JNIEnv* env, SkImageDecoder::Format format) { { SkImageDecoder::kWBMP_Format, "image/vnd.wap.wbmp" } }; - const char* cstr = NULL; + const char* cstr = nullptr; for (size_t i = 0; i < SK_ARRAY_COUNT(gMimeTypes); i++) { if (gMimeTypes[i].fFormat == format) { cstr = gMimeTypes[i].fMimeType; @@ -71,8 +71,10 @@ jstring getMimeTypeString(JNIEnv* env, SkImageDecoder::Format format) { } } - jstring jstr = 0; - if (NULL != cstr) { + jstring jstr = nullptr; + if (cstr != nullptr) { + // NOTE: Caller should env->ExceptionCheck() for OOM + // (can't check for nullptr as it's a valid return value) jstr = env->NewStringUTF(cstr); } return jstr; @@ -323,10 +325,13 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding // update options (if any) if (options != NULL) { + jstring mimeType = getMimeTypeString(env, decoder->getFormat()); + if (env->ExceptionCheck()) { + return nullObjectReturn("OOM in getMimeTypeString()"); + } env->SetIntField(options, gOptions_widthFieldID, scaledWidth); env->SetIntField(options, gOptions_heightFieldID, scaledHeight); - env->SetObjectField(options, gOptions_mimeFieldID, - getMimeTypeString(env, decoder->getFormat())); + env->SetObjectField(options, gOptions_mimeFieldID, mimeType); } // if we're in justBounds mode, return now (skip the java bitmap) -- cgit v1.1