[vlc-devel] [PATCH] src: Avoid infinite loop

Rémi Denis-Courmont remi at remlab.net
Sun Mar 25 08:42:49 CEST 2012


On Sat, 24 Mar 2012 19:37:52 -0400, Edward Wang
<edward.c.wang at compdigitec.com> wrote:
> "while (s != 0)" will never exit if haystack decreases
> 
> Close #6283
> ---
>  Specifically, the problem occurs when vlc_strcasestr() tries to compare
>  "\304rzte" and while (s != 0) never exits because "haystack += s;"
>  combined with "s = -1" causes it to go backwards
> 
>  src/text/unicode.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/src/text/unicode.c b/src/text/unicode.c
> index 789d0a1..8b06a35 100644
> --- a/src/text/unicode.c
> +++ b/src/text/unicode.c
> @@ -235,6 +235,9 @@ char *vlc_strcasestr (const char *haystack, const
char
> *needle)
>          }
>  
>          s = vlc_towc (haystack, &(uint32_t) { 0 });
> +        /* if s is negative (an invalid UTF-8 sequence), don't go
> backwards */
> +        if (s < 0)
> +            s = 1;

I am not convinced that this hack is a correct solution.

And it definitely is not the real problem. In this case, the m3u parser
probably fails to validate its input correctly. You're not supposed to
inject non-UTF-8 sequences into the playlist.

>          haystack += s;
>      }
>      while (s != 0);

-- 
Rémi Denis-Courmont
Sent from my collocated server



More information about the vlc-devel mailing list