Skip to content

Commit 241b87f

Browse files
LeonScrogginsLordNerevar
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 326c591 commit 241b87f

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

core/jni/android/graphics/Bitmap.cpp

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

491-
SkBitmap* bitmap = new SkBitmap;
491+
SkAutoTDelete<SkBitmap> bitmap(new SkBitmap);
492492

493-
bitmap->setConfig(config, width, height, rowBytes);
493+
if (!bitmap->setConfig(config, width, height, rowBytes)) {
494+
return NULL;
495+
}
494496

495497
SkColorTable* ctable = NULL;
496498
if (config == SkBitmap::kIndex8_Config) {
497499
int count = p->readInt32();
500+
if (count < 0 || count > 256) {
501+
// The data is corrupt, since SkColorTable enforces a value between 0 and 256,
502+
// inclusive.
503+
return NULL;
504+
}
498505
if (count > 0) {
499506
size_t size = count * sizeof(SkPMColor);
500507
const SkPMColor* src = (const SkPMColor*)p->readInplace(size);
508+
if (src == NULL) {
509+
return NULL;
510+
}
501511
ctable = new SkColorTable(src, count);
502512
}
503513
}
504514

505-
jbyteArray buffer = GraphicsJNI::allocateJavaPixelRef(env, bitmap, ctable);
515+
jbyteArray buffer = GraphicsJNI::allocateJavaPixelRef(env, bitmap.get(), ctable);
506516
if (NULL == buffer) {
507517
SkSafeUnref(ctable);
508-
delete bitmap;
509518
return NULL;
510519
}
511520

@@ -517,7 +526,6 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
517526
android::status_t status = p->readBlob(size, &blob);
518527
if (status) {
519528
doThrowRE(env, "Could not read bitmap from parcel blob.");
520-
delete bitmap;
521529
return NULL;
522530
}
523531

@@ -527,8 +535,8 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
527535

528536
blob.release();
529537

530-
return GraphicsJNI::createBitmap(env, bitmap, buffer, getPremulBitmapCreateFlags(isMutable),
531-
NULL, NULL, density);
538+
return GraphicsJNI::createBitmap(env, bitmap.detach(), buffer,
539+
getPremulBitmapCreateFlags(isMutable), NULL, NULL, density);
532540
}
533541

534542
static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,

0 commit comments

Comments
 (0)