av_stristr(s, "") returns s, so with an empty 'from' the search pointer
never advanced and the loop appended 'to' to the AVBPrint forever, growing
memory until the process was killed. Return a copy of the input string in
that degenerate case, which matches the intuitive semantics of replacing an
empty substring.

Signed-off-by: Anas Khan <[email protected]>
---
 libavutil/avstring.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 281c5cdc88..d8c72a7c77 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -234,6 +234,9 @@ char *av_strireplace(const char *str, const char *from, 
const char *to)
     size_t tolen = strlen(to), fromlen = strlen(from);
     AVBPrint pbuf;
 
+    if (!fromlen)
+        return av_strdup(str);
+
     av_bprint_init(&pbuf, 1, AV_BPRINT_SIZE_UNLIMITED);
     while ((pstr2 = av_stristr(pstr, from))) {
         av_bprint_append_data(&pbuf, pstr, pstr2 - pstr);
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to