From 436998b020317661dfe1c3b58c8003211f68a7aa Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Wed, 2 Nov 2022 11:42:33 -0600 Subject: [PATCH] MediaCodec: check for exceptions when creating crypto info NativeCryptoInfo's constructor may throw an exception, which means that pieces of `cryptoInfo` won't be properly initialized. Check for that here and let it bubble up. Bug: 206470603 Test: TreeHugger Change-Id: Ifcd15a9ac70f5cfa979c58c84461a37a3a03ef90 --- media/jni/android_media_MediaCodec.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/media/jni/android_media_MediaCodec.cpp b/media/jni/android_media_MediaCodec.cpp index 1183ca3b49777..fafa74bd6394a 100644 --- a/media/jni/android_media_MediaCodec.cpp +++ b/media/jni/android_media_MediaCodec.cpp @@ -2432,13 +2432,12 @@ static void android_media_MediaCodec_native_queueLinearBlock( throwExceptionAsNecessary(env, BAD_VALUE); return; } - NativeCryptoInfo cryptoInfo = [env, cryptoInfoObj, size]{ - if (cryptoInfoObj == nullptr) { - return NativeCryptoInfo{size}; - } else { - return NativeCryptoInfo{env, cryptoInfoObj}; - } - }(); + auto cryptoInfo = + cryptoInfoObj ? NativeCryptoInfo{size} : NativeCryptoInfo{env, cryptoInfoObj}; + if (env->ExceptionCheck()) { + // Creation of cryptoInfo failed. Let the exception bubble up. + return; + } err = codec->queueEncryptedLinearBlock( index, memory,