Skip to content

Commit 54602ec

Browse files
LeonScrogginsThe Android Automerger
authored andcommitted
Make Bitmap_createFromParcel check the color count. DO NOT MERGE
When reading from the parcel, if the number of colors is invalid, early exit. Add two more checks: setInfo must return true, and Parcel::readInplace must return non-NULL. The former ensures that the previously read values (width, height, etc) were valid, and the latter checks that the Parcel had enough data even if the number of colors was reasonable. Also use an auto-deleter to handle deletion of the SkBitmap. Cherry pick from change-Id: Icbd562d6d1f131a723724883fd31822d337cf5a6 BUG=19666945 Change-Id: Iab0d218c41ae0c39606e333e44cda078eef32291
1 parent 69f2910 commit 54602ec

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

core/jni/android/graphics/Bitmap.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -575,24 +575,33 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
575575
return NULL;
576576
}
577577

578-
SkBitmap* bitmap = new SkBitmap;
578+
SkAutoTDelete<SkBitmap> bitmap(new SkBitmap);
579579

580-
bitmap->setInfo(SkImageInfo::Make(width, height, colorType, alphaType), rowBytes);
580+
if (!bitmap->setInfo(SkImageInfo::Make(width, height, colorType, alphaType), rowBytes)) {
581+
return NULL;
582+
}
581583

582584
SkColorTable* ctable = NULL;
583585
if (colorType == kIndex_8_SkColorType) {
584586
int count = p->readInt32();
587+
if (count < 0 || count > 256) {
588+
// The data is corrupt, since SkColorTable enforces a value between 0 and 256,
589+
// inclusive.
590+
return NULL;
591+
}
585592
if (count > 0) {
586593
size_t size = count * sizeof(SkPMColor);
587594
const SkPMColor* src = (const SkPMColor*)p->readInplace(size);
595+
if (src == NULL) {
596+
return NULL;
597+
}
588598
ctable = new SkColorTable(src, count);
589599
}
590600
}
591601

592-
jbyteArray buffer = GraphicsJNI::allocateJavaPixelRef(env, bitmap, ctable);
602+
jbyteArray buffer = GraphicsJNI::allocateJavaPixelRef(env, bitmap.get(), ctable);
593603
if (NULL == buffer) {
594604
SkSafeUnref(ctable);
595-
delete bitmap;
596605
return NULL;
597606
}
598607

@@ -604,7 +613,6 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
604613
android::status_t status = p->readBlob(size, &blob);
605614
if (status) {
606615
doThrowRE(env, "Could not read bitmap from parcel blob.");
607-
delete bitmap;
608616
return NULL;
609617
}
610618

@@ -614,8 +622,8 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
614622

615623
blob.release();
616624

617-
return GraphicsJNI::createBitmap(env, bitmap, buffer, getPremulBitmapCreateFlags(isMutable),
618-
NULL, NULL, density);
625+
return GraphicsJNI::createBitmap(env, bitmap.detach(), buffer,
626+
getPremulBitmapCreateFlags(isMutable), NULL, NULL, density);
619627
}
620628

621629
static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,

0 commit comments

Comments
 (0)