From a77c8dff43641711f54c4f371292c341bebe3463 Mon Sep 17 00:00:00 2001 From: Chih-Yu Huang Date: Fri, 11 Dec 2020 13:17:45 +0900 Subject: [PATCH] MediaMetadataRetriever: Fix null pointer exception This CL fixes a null pointer exception by adding a null check. Bug: 170357507 Test: run android.media.cts.ThumbnailUtilsTest and no crash Change-Id: I60645e4382700993ff7e1bc992b970d89b5b600e (cherry picked from commit fc24bd264ef1f599efa834fc120bc6d1ed304af3) --- media/jni/android_media_MediaMetadataRetriever.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/media/jni/android_media_MediaMetadataRetriever.cpp b/media/jni/android_media_MediaMetadataRetriever.cpp index 126897a908f88..ddc51cdb861c5 100644 --- a/media/jni/android_media_MediaMetadataRetriever.cpp +++ b/media/jni/android_media_MediaMetadataRetriever.cpp @@ -464,11 +464,13 @@ static jobject android_media_MediaMetadataRetriever_getThumbnailImageAtIndex( || thumbPixels * 6 >= maxPixels) { frameMemory = retriever->getImageAtIndex( index, colorFormat, false /*metaOnly*/, true /*thumbnail*/); - // TODO: Using unsecurePointer() has some associated security pitfalls - // (see declaration for details). - // Either document why it is safe in this case or address the - // issue (e.g. by copying). - videoFrame = static_cast(frameMemory->unsecurePointer()); + if (frameMemory != 0) { + // TODO: Using unsecurePointer() has some associated security pitfalls + // (see declaration for details). + // Either document why it is safe in this case or address the + // issue (e.g. by copying). + videoFrame = static_cast(frameMemory->unsecurePointer()); + } if (thumbPixels > maxPixels) { int downscale = ceil(sqrt(thumbPixels / (float)maxPixels));