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

Commit 0a6a0e9e authored by Ray Chen's avatar Ray Chen Committed by The Android Open Source Project
Browse files

AI 144176: To fix the race condition in case "requestCancelDecode"

  happens earlier than AutoDecoderCancel object is added
  to the gAutoDecoderCancelMutex linked list.
  BUG=1692286

Automated import of CL 144176
parent 0827c814
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ static jfieldID gOptions_ditherFieldID;
static jfieldID gOptions_widthFieldID;
static jfieldID gOptions_heightFieldID;
static jfieldID gOptions_mimeFieldID;
static jfieldID gOptions_mCancelID;

static jclass gFileDescriptor_class;
static jfieldID gFileDescriptor_descriptor;
@@ -322,6 +323,15 @@ static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding,
    
    AutoDecoderCancel   adc(options, decoder);

    // To fix the race condition in case "requestCancelDecode"
    // happens earlier than AutoDecoderCancel object is added
    // to the gAutoDecoderCancelMutex linked list.
    if (NULL != options) {
        if (env->GetBooleanField(options, gOptions_mCancelID)) {
            return NULL;
        }
    }

    if (!decoder->decode(stream, bitmap, prefConfig, mode)) {
        return NULL;
    }
@@ -588,6 +598,7 @@ int register_android_graphics_BitmapFactory(JNIEnv* env) {
    gOptions_widthFieldID = getFieldIDCheck(env, gOptions_class, "outWidth", "I");
    gOptions_heightFieldID = getFieldIDCheck(env, gOptions_class, "outHeight", "I");
    gOptions_mimeFieldID = getFieldIDCheck(env, gOptions_class, "outMimeType", "Ljava/lang/String;");
    gOptions_mCancelID = getFieldIDCheck(env, gOptions_class, "mCancel", "Z");

    gFileDescriptor_class = make_globalref(env, "java/io/FileDescriptor");
    gFileDescriptor_descriptor = getFieldIDCheck(env, gFileDescriptor_class, "descriptor", "I");