aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/GifTest.cpp
diff options
context:
space:
mode:
authorGravatar Leon Scroggins III <scroggo@google.com>2016-12-08 11:54:04 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-12-09 15:04:06 +0000
commit4993b95f532fdfc1996809189aa7e24ee839d983 (patch)
treea6eb7a774a46a9b9327f3c1fcd43994e14354441 /tests/GifTest.cpp
parent92a895e66378527e6e33b825dc6528235e7c76bd (diff)
Do not create SkGifCodec if true size is not known
If there is enough data in the stream to read the reported canvas size, but not enough to read the first image's header, we do not know the true canvas size, since we may expand it to fit the first frame. In that case, return nullptr from NewFromStream. Add a test. SkGifCodec.cpp: Correct a comment - parse returns false if there is a fatal error. parse() returning true does not guarantee that the size was found. Instead of checking the width and height, check to see whether the first frame exists and has its header defined. If not, we do not yet know the true canvas size. Assert that the canvas size is non-zero, which is a fatal error from parse. SkGifImageReader.cpp: Move the code to set the header defined before the SkGIFSizeQuery exit condition. This allows SkGifCodec to check the first frame's header to determine whether the size is known. GifTest.cpp: Add a test which truncates the file just before the image header (and after the global header). Prior to the other changes, this would create an SkCodec. For an image that needs its canvas size expanded, the SkCodec would have an incorrect size. CodecPartialTest.cpp: randPixels.gif now needs more than half of its data to create an SkCodec, so set a minimum for test_partial. Change-Id: I40482f524128b2f1fe59b8f27dd64c7cbe793079 Reviewed-on: https://skia-review.googlesource.com/5701 Reviewed-by: Derek Sollenberger <djsollen@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'tests/GifTest.cpp')
-rw-r--r--tests/GifTest.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/GifTest.cpp b/tests/GifTest.cpp
index b06d3ead1c..17dce92186 100644
--- a/tests/GifTest.cpp
+++ b/tests/GifTest.cpp
@@ -227,3 +227,15 @@ DEF_TEST(Gif_Sampled, r) {
bm.rowBytes(), &options);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
}
+
+// If a GIF file is truncated before the header for the first image is defined,
+// we should not create an SkCodec.
+DEF_TEST(Codec_GifTruncated, r) {
+ SkString path = GetResourcePath("test640x479.gif");
+ sk_sp<SkData> data(SkData::MakeFromFileName(path.c_str()));
+
+ // This is right before the header for the first image.
+ data = SkData::MakeSubset(data.get(), 0, 446);
+ std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
+ REPORTER_ASSERT(r, !codec);
+}