Skip to content

Commit 35ef567

Browse files
nazgeejredestig
authored andcommitted
Fix SkBitmap::fPixels not being locked correctly
In some cases bitmap's pixels where freed during encoding, which caused a null pointer dereference. This fix makes sure that underlaying buffer is locked for the whole process of compression. Change-Id: I0ac56821f5d333072271dc2670fa30f1562adfa3
1 parent ad955fe commit 35ef567

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

core/jni/android/graphics/Bitmap.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,18 @@ static bool Bitmap_compress(JNIEnv* env, jobject clazz, SkBitmap* bitmap,
298298
}
299299

300300
bool success = false;
301-
SkWStream* strm = CreateJavaOutputStreamAdaptor(env, jstream, jstorage);
302-
if (NULL != strm) {
301+
if (NULL != bitmap) {
302+
SkAutoLockPixels alp(*bitmap);
303+
304+
if (NULL == bitmap->getPixels()) {
305+
return false;
306+
}
307+
308+
SkWStream* strm = CreateJavaOutputStreamAdaptor(env, jstream, jstorage);
309+
if (NULL == strm) {
310+
return false;
311+
}
312+
303313
SkImageEncoder* encoder = SkImageEncoder::Create(fm);
304314
if (NULL != encoder) {
305315
success = encoder->encodeStream(strm, *bitmap, quality);

0 commit comments

Comments
 (0)