diff mbox series

[FFmpeg-devel,5/6] avfilter/vf_drawtext: use replacement chars for invalid UTF8 sequences

Message ID 20200129233235.3325-5-cus@passwd.hu
State Accepted
Headers show
Series [FFmpeg-devel,1/6] avutil/common: use unsigned int in GET_UTF8
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Marton Balint Jan. 29, 2020, 11:32 p.m. UTC
continue is explicitly disallowed for GET_UTF8, so let's fix that as well.
Fixes crash with invalid UTF8 sequences.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavfilter/vf_drawtext.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Paul B Mahol Jan. 30, 2020, 10:37 a.m. UTC | #1
probably ok

On 1/30/20, Marton Balint <cus@passwd.hu> wrote:
> continue is explicitly disallowed for GET_UTF8, so let's fix that as well.
> Fixes crash with invalid UTF8 sequences.
>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  libavfilter/vf_drawtext.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
> index aea17b6793..ed10175af0 100644
> --- a/libavfilter/vf_drawtext.c
> +++ b/libavfilter/vf_drawtext.c
> @@ -1225,7 +1225,8 @@ static int draw_glyphs(DrawTextContext *s, AVFrame
> *frame,
>      for (i = 0, p = text; *p; i++) {
>          FT_Bitmap bitmap;
>          Glyph dummy = { 0 };
> -        GET_UTF8(code, *p++, continue;);
> +        GET_UTF8(code, *p++, code = 0xfffd; goto continue_on_invalid;);
> +continue_on_invalid:
>
>          /* skip new line chars, just go to new line */
>          if (code == '\n' || code == '\r' || code == '\t')
> @@ -1363,7 +1364,8 @@ static int draw_text(AVFilterContext *ctx, AVFrame
> *frame,
>
>      /* load and cache glyphs */
>      for (i = 0, p = text; *p; i++) {
> -        GET_UTF8(code, *p++, continue;);
> +        GET_UTF8(code, *p++, code = 0xfffd; goto continue_on_invalid;);
> +continue_on_invalid:
>
>          /* get glyph */
>          dummy.code = code;
> @@ -1386,7 +1388,8 @@ static int draw_text(AVFilterContext *ctx, AVFrame
> *frame,
>      /* compute and save position for each glyph */
>      glyph = NULL;
>      for (i = 0, p = text; *p; i++) {
> -        GET_UTF8(code, *p++, continue;);
> +        GET_UTF8(code, *p++, code = 0xfffd; goto continue_on_invalid2;);
> +continue_on_invalid2:
>
>          /* skip the \n in the sequence \r\n */
>          if (prev_code == '\r' && code == '\n')
> --
> 2.16.4
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index aea17b6793..ed10175af0 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -1225,7 +1225,8 @@  static int draw_glyphs(DrawTextContext *s, AVFrame *frame,
     for (i = 0, p = text; *p; i++) {
         FT_Bitmap bitmap;
         Glyph dummy = { 0 };
-        GET_UTF8(code, *p++, continue;);
+        GET_UTF8(code, *p++, code = 0xfffd; goto continue_on_invalid;);
+continue_on_invalid:
 
         /* skip new line chars, just go to new line */
         if (code == '\n' || code == '\r' || code == '\t')
@@ -1363,7 +1364,8 @@  static int draw_text(AVFilterContext *ctx, AVFrame *frame,
 
     /* load and cache glyphs */
     for (i = 0, p = text; *p; i++) {
-        GET_UTF8(code, *p++, continue;);
+        GET_UTF8(code, *p++, code = 0xfffd; goto continue_on_invalid;);
+continue_on_invalid:
 
         /* get glyph */
         dummy.code = code;
@@ -1386,7 +1388,8 @@  static int draw_text(AVFilterContext *ctx, AVFrame *frame,
     /* compute and save position for each glyph */
     glyph = NULL;
     for (i = 0, p = text; *p; i++) {
-        GET_UTF8(code, *p++, continue;);
+        GET_UTF8(code, *p++, code = 0xfffd; goto continue_on_invalid2;);
+continue_on_invalid2:
 
         /* skip the \n in the sequence \r\n */
         if (prev_code == '\r' && code == '\n')