From patchwork Sat Mar 13 21:33:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 26383 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id F1D7E44A6CC for ; Sat, 13 Mar 2021 23:35:05 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D8D1368ACEF; Sat, 13 Mar 2021 23:35:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ED4E268ACE8 for ; Sat, 13 Mar 2021 23:34:58 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A6E00E50EC; Sat, 13 Mar 2021 22:34:58 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yy38VyliJTof; Sat, 13 Mar 2021 22:34:28 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 6A516E50EE; Sat, 13 Mar 2021 22:34:04 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Mar 2021 22:33:41 +0100 Message-Id: <20210313213345.3268-4-cus@passwd.hu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210313213345.3268-1-cus@passwd.hu> References: <20210313213345.3268-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/8] avcodec/realtextdec: do not overread if zero padding is missing X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavcodec/realtextdec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/realtextdec.c b/libavcodec/realtextdec.c index 5084781123..bdd9659235 100644 --- a/libavcodec/realtextdec.c +++ b/libavcodec/realtextdec.c @@ -29,11 +29,11 @@ #include "libavutil/avstring.h" #include "libavutil/bprint.h" -static int rt_event_to_ass(AVBPrint *buf, const char *p) +static int rt_event_to_ass(AVBPrint *buf, const char *p, const char *pend) { int prev_chr_is_space = 1; - while (*p) { + while (p < pend && *p) { if (*p != '<') { if (!av_isspace(*p)) av_bprint_chars(buf, *p, 1); @@ -41,7 +41,7 @@ static int rt_event_to_ass(AVBPrint *buf, const char *p) av_bprint_chars(buf, ' ', 1); prev_chr_is_space = av_isspace(*p); } else { - const char *end = strchr(p, '>'); + const char *end = av_strnstr(p, ">", pend - p); if (!end) break; if (!av_strncasecmp(p, "
", 5) || @@ -65,7 +65,7 @@ static int realtext_decode_frame(AVCodecContext *avctx, AVBPrint buf; av_bprint_init(&buf, 0, 4096); - if (ptr && avpkt->size > 0 && !rt_event_to_ass(&buf, ptr)) + if (ptr && avpkt->size > 0 && !rt_event_to_ass(&buf, ptr, ptr + avpkt->size)) ret = ff_ass_add_rect(sub, buf.str, s->readorder++, 0, NULL, NULL); av_bprint_finalize(&buf, NULL); if (ret < 0)