diff --git a/frameworks/innerkitsimpl/test/unittest/plugin_test/ext_decoder_test.cpp b/frameworks/innerkitsimpl/test/unittest/plugin_test/ext_decoder_test.cpp index 80f9b6493c38f0b4086cf8fb686c35c5fc895c8b..aa873019fa7fec60acdffed8e704036743299e64 100644 --- a/frameworks/innerkitsimpl/test/unittest/plugin_test/ext_decoder_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/plugin_test/ext_decoder_test.cpp @@ -65,6 +65,7 @@ static const std::string IMAGE_DEST = "/data/local/tmp/image/test_encode_out.dat static const std::string IMAGE_HEIFHDR_SRC = "/data/local/tmp/image/test_heif_hdr.heic"; static const std::string IMAGE_JPG_THREE_GAINMAP_HDR_PATH = "/data/local/tmp/image/three_gainmap_hdr.jpg"; static const std::string IMAGE_HEIC_THREE_GAINMAP_HDR_PATH = "/data/local/tmp/image/three_gainmap_hdr.heic"; +static const std::string IMAGE_INCOMPLETE_GIF_PATH = "/data/local/tmp/image/test_broken.gif"; class ExtDecoderTest : public testing::Test { public: ExtDecoderTest() {} @@ -2333,5 +2334,23 @@ HWTEST_F(ExtDecoderTest, EncodeWideGamutPixelMapAndDecodeTest004, TestSize.Level ASSERT_EQ(pixelmap, nullptr); } +/** + * @tc.name: DecodeIncompleteGifImageTest001 + * @tc.desc: Test decoding broken gif image. + * @tc.type: FUNC + */ +HWTEST_F(ExtDecoderTest, DecodeIncompleteGifImageTest001, TestSize.Level3) +{ + uint32_t errorCode = 0; + SourceOptions sourceOpts; + std::unique_ptr imageSource = + ImageSource::CreateImageSource(IMAGE_INCOMPLETE_GIF_PATH.c_str(), sourceOpts, errorCode); + ASSERT_NE(imageSource, nullptr); + DecodeOptions opts; + std::shared_ptr pixelmap = imageSource->CreatePixelMap(opts, errorCode); + EXPECT_EQ(errorCode, OHOS::Media::SUCCESS); + EXPECT_NE(pixelmap, nullptr); +} + } } \ No newline at end of file diff --git a/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp b/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp index 6a43f38682e65b82b4812eb88cb39eb999eb42cf..de64961b55da337cee1528e4f8dc6237537b6467 100644 --- a/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp +++ b/plugins/common/libs/image/libextplugin/src/ext_decoder.cpp @@ -1823,11 +1823,16 @@ uint32_t ExtDecoder::GetFramePixels(SkImageInfo& info, uint8_t* buffer, uint64_t bool cond = buffer == nullptr; CHECK_ERROR_RETURN_RET_LOG(cond, ERR_IMAGE_DECODE_ABNORMAL, "get pixels failed, buffer is nullptr"); SkCodec::Result ret = codec_->getPixels(info, buffer, rowStride, &options); - if (ret != SkCodec::kSuccess && ResetCodec()) { - // Try again - ret = codec_->getPixels(info, buffer, rowStride, &options); + if (ret == SkCodec::kIncompleteInput || ret == SkCodec::kErrorInInput) { + IMAGE_LOGI("Decode broken data success. Triggered kIncompleteInput feature of skia!"); + return SUCCESS; + } else if (ret == SkCodec::kSuccess) { + return SUCCESS; } - cond = ret != SkCodec::kSuccess; + // Try again + ResetCodec(); + ret = codec_->getPixels(info, buffer, rowStride, &options); + cond = (ret != SkCodec::kSuccess && ret != SkCodec::kIncompleteInput && ret != SkCodec::kErrorInInput); CHECK_ERROR_RETURN_RET_LOG(cond, ERR_IMAGE_DECODE_ABNORMAL, "Gif decode failed, get pixels failed, ret=%{public}d", ret); return SUCCESS; diff --git a/test/resource/image/images/test_broken.gif b/test/resource/image/images/test_broken.gif new file mode 100644 index 0000000000000000000000000000000000000000..f3e3f6362f24134eb4797978b92bba35cdc26142 Binary files /dev/null and b/test/resource/image/images/test_broken.gif differ diff --git a/test/resource/image/ohos_test.xml b/test/resource/image/ohos_test.xml index f325e6d63aeb47d854f50a039e9cbd83683b394e..afd187e12c4f0c38bd6e8a6f9c5b6eb7db919f03 100644 --- a/test/resource/image/ohos_test.xml +++ b/test/resource/image/ohos_test.xml @@ -121,6 +121,7 @@