Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: src/core/SkPictureData.cpp

Issue 1308273011: Handle zero-length encoded images gracefully during deserialization (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: use an image generator Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkWriteBuffer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPictureData.cpp
diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp
index 5089e5d8d6240f7d3542a933ddef3d7c9e688373..7686dd4e01d7217b7ef72b86f656a3fc06dedd2c 100644
--- a/src/core/SkPictureData.cpp
+++ b/src/core/SkPictureData.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
#include <new>
+#include "SkImageGenerator.h"
#include "SkPictureData.h"
#include "SkPictureRecord.h"
#include "SkReadBuffer.h"
@@ -433,6 +434,18 @@ bool SkPictureData::parseStreamTag(SkStream* stream,
return true; // success
}
+namespace {
+
+class EmptyImageGenerator final : public SkImageGenerator {
reed1 2015/09/04 18:17:27 // This guy intentionally should always fail on al
f(malita) 2015/09/04 18:23:54 Done.
+public:
+ EmptyImageGenerator(const SkImageInfo& info) : INHERITED(info) { }
+
+private:
+ typedef SkImageGenerator INHERITED;
+};
+
+} // anonymous namespace
+
static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) {
int width = buffer.read32();
int height = buffer.read32();
@@ -442,9 +455,15 @@ static const SkImage* create_image_from_buffer(SkReadBuffer& buffer) {
}
SkAutoTUnref<SkData> encoded(buffer.readByteArrayAsData());
+ if (encoded->size() == 0) {
+ // The image could not be encoded at serialization time - return an empty placeholder.
+ return SkImage::NewFromGenerator(
+ new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height)));
+ }
+
int originX = buffer.read32();
int originY = buffer.read32();
- if (0 == encoded->size() || originX < 0 || originY < 0) {
+ if (originX < 0 || originY < 0) {
buffer.validate(false);
return nullptr;
}
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkWriteBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698