The solution should be using WebPMemoryWriterClear(&writer); instead of free(writer.mem); ,acording to the libwebp 's comment
// The custom writer to be used with WebPMemoryWriter as custom_ptr. Upon
// completion, writer.mem and writer.size will hold the coded data.
// writer.mem must be freed by calling WebPMemoryWriterClear.
WEBP_EXTERN int WebPMemoryWrite(const uint8_t* data, size_t data_size,
const WebPPicture* picture);
So the solution may be add libwebp.dependency 'libwebp','>= 1.3.2' to libwebp subspec and replace YYCGImageCreateEncodedWebPData's implementation. I will make a PR later today.
libwebp has an important vulnerability called CVE-2023-4863, and it is fixed in 1.3.2 for webp. You can see more datils in WebP 堆缓冲区溢出 安全漏洞
crash stack maybe like:
The solution should be using
WebPMemoryWriterClear(&writer);
instead offree(writer.mem);
,acording to the libwebp 's commentSo the solution may be add
libwebp.dependency 'libwebp','>= 1.3.2'
to libwebp subspec and replace YYCGImageCreateEncodedWebPData's implementation. I will make a PR later today.