From e726e7ca0c99c75f447e6c22b7d341ce921c4e50 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Tue, 18 Jul 2017 16:22:52 -0400 Subject: Report first GIF frame after knowing its meta data Previously, we reported the first image as soon as it was available. As a result, in crrev.com/2565323003, InitializeNewFrame might be called before the metadata is known, meaning it would read the wrong metadata. Instead of looking at the imagesCount(), SkGifCodec::NewFromStream looks at frameContext(0), which may still exist even if it's not yet counted in imagesCount(). Add a test that confirms the desired behavior. Change-Id: Ib392721ecd2218ba0fcd35aaa64117c0ba3e4ea6 Reviewed-on: https://skia-review.googlesource.com/24405 Reviewed-by: Derek Sollenberger Commit-Queue: Leon Scroggins --- tests/GifTest.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'tests/GifTest.cpp') diff --git a/tests/GifTest.cpp b/tests/GifTest.cpp index 7728d27dcb..5749df1be5 100644 --- a/tests/GifTest.cpp +++ b/tests/GifTest.cpp @@ -251,11 +251,34 @@ DEF_TEST(Gif_Sampled, r) { // 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 data(SkData::MakeFromFileName(path.c_str())); + sk_sp data(GetResourceAsData("test640x479.gif")); + if (!data) { + return; + } // This is right before the header for the first image. data = SkData::MakeSubset(data.get(), 0, 446); std::unique_ptr codec(SkCodec::NewFromData(data)); REPORTER_ASSERT(r, !codec); } + +DEF_TEST(Codec_GifTruncated2, r) { + sk_sp data(GetResourceAsData("box.gif")); + if (!data) { + return; + } + + // This is after the header, but before the color table. + data = SkData::MakeSubset(data.get(), 0, 23); + std::unique_ptr codec(SkCodec::NewFromData(data)); + if (!codec) { + ERRORF(r, "Failed to create codec with partial data"); + return; + } + + // Although we correctly created a codec, no frame is + // complete enough that it has its metadata. Returning 0 + // ensures that Chromium will not try to create a frame + // too early. + REPORTER_ASSERT(r, codec->getFrameCount() == 0); +} -- cgit v1.2.3