summaryrefslogtreecommitdiffstats
path: root/core/jni/android
diff options
context:
space:
mode:
authorLeon Scroggins III <scroggo@google.com>2015-03-11 13:12:06 -0400
committerLeon Scroggins <scroggo@google.com>2015-03-11 17:34:51 +0000
commitec419e0b731d2aa32f7f570e4021fe18b8be228d (patch)
treead77c59e8fd8aea64cc838570682f9c9be3fc02a /core/jni/android
parent4771577a342214ef4f7373a8d37d015749b00347 (diff)
downloadframeworks_base-ec419e0b731d2aa32f7f570e4021fe18b8be228d.zip
frameworks_base-ec419e0b731d2aa32f7f570e4021fe18b8be228d.tar.gz
frameworks_base-ec419e0b731d2aa32f7f570e4021fe18b8be228d.tar.bz2
Make Bitmap_createFromParcel check the color count.
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. BUG=19666945 Change-Id: Icbd562d6d1f131a723724883fd31822d337cf5a6
Diffstat (limited to 'core/jni/android')
-rwxr-xr-xcore/jni/android/graphics/Bitmap.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp
index a10cfca..7a934bd 100755
--- a/core/jni/android/graphics/Bitmap.cpp
+++ b/core/jni/android/graphics/Bitmap.cpp
@@ -556,24 +556,33 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
return NULL;
}
- SkBitmap* bitmap = new SkBitmap;
+ std::unique_ptr<SkBitmap> bitmap(new SkBitmap);
- bitmap->setInfo(SkImageInfo::Make(width, height, colorType, alphaType), rowBytes);
+ if (!bitmap->setInfo(SkImageInfo::Make(width, height, colorType, alphaType), rowBytes)) {
+ return NULL;
+ }
SkColorTable* ctable = NULL;
if (colorType == kIndex_8_SkColorType) {
int count = p->readInt32();
+ if (count < 0 || count > 256) {
+ // The data is corrupt, since SkColorTable enforces a value between 0 and 256,
+ // inclusive.
+ return NULL;
+ }
if (count > 0) {
size_t size = count * sizeof(SkPMColor);
const SkPMColor* src = (const SkPMColor*)p->readInplace(size);
+ if (src == NULL) {
+ return NULL;
+ }
ctable = new SkColorTable(src, count);
}
}
- jbyteArray buffer = GraphicsJNI::allocateJavaPixelRef(env, bitmap, ctable);
+ jbyteArray buffer = GraphicsJNI::allocateJavaPixelRef(env, bitmap.get(), ctable);
if (NULL == buffer) {
SkSafeUnref(ctable);
- delete bitmap;
return NULL;
}
@@ -585,7 +594,6 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
android::status_t status = p->readBlob(size, &blob);
if (status) {
doThrowRE(env, "Could not read bitmap from parcel blob.");
- delete bitmap;
return NULL;
}
@@ -595,8 +603,8 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
blob.release();
- return GraphicsJNI::createBitmap(env, bitmap, buffer, getPremulBitmapCreateFlags(isMutable),
- NULL, NULL, density);
+ return GraphicsJNI::createBitmap(env, bitmap.release(), buffer,
+ getPremulBitmapCreateFlags(isMutable), NULL, NULL, density);
}
static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,