Insert an empty image when we cannot decode
authorscroggo <scroggo@google.com>
Fri, 19 Feb 2016 20:08:41 +0000 (12:08 -0800)
committerCommit bot <commit-bot@chromium.org>
Fri, 19 Feb 2016 20:08:41 +0000 (12:08 -0800)
In SKP deserialization, if there is a 0 byte encoded image, we insert
an empty image into the output SkPicture so that we can continue
deserializing. Do the same when our decoder cannot decode it. This may
be the result of a bug in our decoder, or in the stream serialization.
But it should not mean the entire stream is invalid.

BUG=skia:4691
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1715853002

Review URL: https://codereview.chromium.org/1715853002

src/core/SkReadBuffer.cpp

index ca89022..6823a6c 100644 (file)
@@ -313,7 +313,13 @@ SkImage* SkReadBuffer::readImage() {
     }
 
     const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height);
-    return SkImage::NewFromEncoded(encoded, &subset);
+    SkImage* image = SkImage::NewFromEncoded(encoded, &subset);
+    if (image) {
+        return image;
+    }
+
+    return SkImage::NewFromGenerator(
+            new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height)));
 }
 
 SkTypeface* SkReadBuffer::readTypeface() {