From 23d812187efefbaf9b62124d77d3fbb1c44853c4 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Thu, 19 Jun 2025 21:49:21 +0300 Subject: [PATCH] Merge pull request #27457 from sturkmen72:WebP-bugfix fix for the issue #27456 #27457 closes #27456 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- modules/imgcodecs/src/grfmt_webp.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/imgcodecs/src/grfmt_webp.cpp b/modules/imgcodecs/src/grfmt_webp.cpp index 2d55995789..3e63dd7acb 100644 --- a/modules/imgcodecs/src/grfmt_webp.cpp +++ b/modules/imgcodecs/src/grfmt_webp.cpp @@ -155,14 +155,16 @@ bool WebPDecoder::readHeader() webp_data.size = data.total(); WebPAnimDecoderOptions dec_options; - WebPAnimDecoderOptionsInit(&dec_options); + if (!WebPAnimDecoderOptionsInit(&dec_options)) + CV_Error(Error::StsInternal, "Failed to initialize animated WebP decoding options"); dec_options.color_mode = m_use_rgb ? MODE_RGBA : MODE_BGRA; anim_decoder.reset(WebPAnimDecoderNew(&webp_data, &dec_options)); CV_Assert(anim_decoder.get() && "Error parsing image"); WebPAnimInfo anim_info; - WebPAnimDecoderGetInfo(anim_decoder.get(), &anim_info); + if (!WebPAnimDecoderGetInfo(anim_decoder.get(), &anim_info)) + CV_Error(Error::StsInternal, "Failed to get animated WebP information"); m_animation.loop_count = anim_info.loop_count; m_animation.bgcolor[0] = (anim_info.bgcolor >> 24) & 0xFF; @@ -216,7 +218,8 @@ bool WebPDecoder::readData(Mat &img) uint8_t* buf; int timestamp; - WebPAnimDecoderGetNext(anim_decoder.get(), &buf, ×tamp); + if (!WebPAnimDecoderGetNext(anim_decoder.get(), &buf, ×tamp)) + CV_Error(Error::StsInternal, "Failed to decode animated WebP frame"); Mat tmp(Size(m_width, m_height), CV_8UC4, buf); if (img.type() == CV_8UC1) @@ -446,7 +449,6 @@ bool WebPEncoder::writeanimation(const Animation& animation, const std::vector