diff options
author | Leon Scroggins III <scroggo@google.com> | 2017-10-05 14:10:20 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-10-05 14:10:20 +0000 |
commit | 6dc9d3e388b954c0f22124a4bf69575c364cb21c (patch) | |
tree | c4fae2ff7d4c6e3d6efd98a81625d5cfb6e3c803 | |
parent | 4ab6ab40cb7b12251f960cc45df2d950c5c36fd4 (diff) | |
parent | 7a3ba537f7456b4870a983cd9e0a09bb3d478efc (diff) | |
download | skia-6dc9d3e388b954c0f22124a4bf69575c364cb21c.tar.gz |
Fix truncated webp images
am: 7a3ba537f7
Change-Id: I015d2904c37c824fd201c05cc589690353d1568b
-rw-r--r-- | src/codec/SkWebpCodec.cpp | 7 | ||||
-rw-r--r-- | tests/CodecTest.cpp | 25 |
2 files changed, 26 insertions, 6 deletions
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp index 21d45da233..a3ba9b04c8 100644 --- a/src/codec/SkWebpCodec.cpp +++ b/src/codec/SkWebpCodec.cpp @@ -583,7 +583,7 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, return kInvalidInput; } - int rowsDecoded; + int rowsDecoded = 0; SkCodec::Result result; switch (WebPIUpdate(idec, frame.fragment.bytes, frame.fragment.size)) { case VP8_STATUS_OK: @@ -591,7 +591,10 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, result = kSuccess; break; case VP8_STATUS_SUSPENDED: - WebPIDecGetRGB(idec, &rowsDecoded, nullptr, nullptr, nullptr); + if (!WebPIDecGetRGB(idec, &rowsDecoded, nullptr, nullptr, nullptr) + || rowsDecoded <= 0) { + return kInvalidInput; + } *rowsDecodedPtr = rowsDecoded + dstY; result = kIncompleteInput; break; diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp index ffaeb2b61c..20c2f03982 100644 --- a/tests/CodecTest.cpp +++ b/tests/CodecTest.cpp @@ -390,10 +390,6 @@ static void check(skiatest::Reporter* r, if (supportsSubsetDecoding) { if (expectedResult == SkCodec::kSuccess) { REPORTER_ASSERT(r, result == expectedResult); - } else { - SkASSERT(expectedResult == SkCodec::kIncompleteInput); - REPORTER_ASSERT(r, result == SkCodec::kIncompleteInput - || result == SkCodec::kSuccess); } // Webp is the only codec that supports subsets, and it will have modified the subset // to have even left/top. @@ -1595,3 +1591,24 @@ DEF_TEST(Codec_EncodeICC, r) { test_encode_icc(r, SkEncodedImageFormat::kJPEG, SkTransferFunctionBehavior::kIgnore); test_encode_icc(r, SkEncodedImageFormat::kWEBP, SkTransferFunctionBehavior::kIgnore); } + +DEF_TEST(Codec_webp_rowsDecoded, r) { + const char* path = "baby_tux.webp"; + sk_sp<SkData> data(GetResourceAsData(path)); + if (!data) { + return; + } + + // Truncate this file so that the header is available but no rows can be + // decoded. This should create a codec but fail to decode. + size_t truncatedSize = 5000; + sk_sp<SkData> subset = SkData::MakeSubset(data.get(), 0, truncatedSize); + std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(std::move(subset))); + if (!codec) { + ERRORF(r, "Failed to create a codec for %s truncated to only %lu bytes", + path, truncatedSize); + return; + } + + test_info(r, codec.get(), codec->getInfo(), SkCodec::kInvalidInput, nullptr); +} |