Skip to content

Commit f702dfd

Browse files
henry.uh_chencodex-corp
authored andcommitted
[Bitmap] Add null pointer protection in Bitmap_sameAs()
Symptom: SkBitmap::getAddr(int, int) may return NULL due to unrecognized config (ex: kRLE_Index8_Config). This will cause memcmp method to crash. Since bm0 and bm1 both have pixel data() (have passed NULL == getPixels() check), those 2 bitmaps should be valid (only unrecognized), we return JNI_FALSE to warn user those 2 unrecognized config bitmaps may be different. Change-Id: I6970c27de412110a3035d0a783112c4cd3ebc35b
1 parent 411e95f commit f702dfd

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

core/jni/android/graphics/Bitmap.cpp

100644100755
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,19 @@ static bool Bitmap_sameAs(JNIEnv* env, jobject, const SkBitmap* bm0,
752752
const int h = bm0->height();
753753
const size_t size = bm0->width() * bm0->bytesPerPixel();
754754
for (int y = 0; y < h; y++) {
755-
if (memcmp(bm0->getAddr(0, y), bm1->getAddr(0, y), size) != 0) {
755+
// SkBitmap::getAddr(int, int) may return NULL due to unrecognized config
756+
// (ex: kRLE_Index8_Config). This will cause memcmp method to crash. Since bm0
757+
// and bm1 both have pixel data() (have passed NULL == getPixels() check),
758+
// those 2 bitmaps should be valid (only unrecognized), we return JNI_FALSE
759+
// to warn user those 2 unrecognized config bitmaps may be different.
760+
void *bm0Addr = bm0->getAddr(0, y);
761+
void *bm1Addr = bm1->getAddr(0, y);
762+
763+
if(bm0Addr == NULL || bm1Addr == NULL) {
764+
return false;
765+
}
766+
767+
if (memcmp(bm0Addr, bm1Addr, size) != 0) {
756768
return false;
757769
}
758770
}

0 commit comments

Comments
 (0)