From a4530ceabcd28914cf824def5b90e00e27265c49 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Fri, 8 Oct 2021 13:45:07 -0700 Subject: [PATCH] Parcel: remove use of getOpenAshmemSize Parcel native pointers are created when the Parcel is created, and they are destroyed in finalize. When a Java object is finalized, we shouldn't be calling methods on this (note - due to the way that compareData is written, it will throw NPE if otherParcel is null - and if this were not the case, the use of getOpenAshmemSize here - which will frequently be zero - would break the comparison here). Bug: 195752513 Test: atest android.os.ParcelTest android.os.cts.ParcelTest Change-Id: Iad86624d6e0aad2ca37273ddbcb456dff7f48d46 --- core/jni/android_os_Parcel.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/core/jni/android_os_Parcel.cpp b/core/jni/android_os_Parcel.cpp index aadd320eb2e10..42ff39535567b 100644 --- a/core/jni/android_os_Parcel.cpp +++ b/core/jni/android_os_Parcel.cpp @@ -596,13 +596,10 @@ static jint android_os_Parcel_compareData(JNIEnv* env, jclass clazz, jlong thisN jlong otherNativePtr) { Parcel* thisParcel = reinterpret_cast(thisNativePtr); - if (thisParcel == NULL) { - return 0; - } + LOG_ALWAYS_FATAL_IF(thisParcel == nullptr, "Should not be null"); + Parcel* otherParcel = reinterpret_cast(otherNativePtr); - if (otherParcel == NULL) { - return thisParcel->getOpenAshmemSize(); - } + LOG_ALWAYS_FATAL_IF(otherParcel == nullptr, "Should not be null"); return thisParcel->compareData(*otherParcel); }