From patchwork Sat Mar 13 21:33:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 26385 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 D1F1E44A6CC for ; Sat, 13 Mar 2021 23:35:35 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B785E68AD18; Sat, 13 Mar 2021 23:35:35 +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 A0FA768ACF7 for ; Sat, 13 Mar 2021 23:35:28 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 74BBEE50EF; Sat, 13 Mar 2021 22:35:28 +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 U4-sgboWRRYo; Sat, 13 Mar 2021 22:34:58 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 5C4F4E50F0; Sat, 13 Mar 2021 22:34:11 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Mar 2021 22:33:43 +0100 Message-Id: <20210313213345.3268-6-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 6/8] avcodec/webvttdec: 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/webvttdec.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/webvttdec.c b/libavcodec/webvttdec.c index 7b2d1750de..43caf3edbd 100644 --- a/libavcodec/webvttdec.c +++ b/libavcodec/webvttdec.c @@ -42,23 +42,23 @@ static const struct { {"&", "&"}, {" ", "\\h"}, }; -static int webvtt_event_to_ass(AVBPrint *buf, const char *p) +static int webvtt_event_to_ass(AVBPrint *buf, const char *p, const char *pend) { int i, again = 0, skip = 0; - while (*p) { + while (p < pend && *p) { for (i = 0; i < FF_ARRAY_ELEMS(webvtt_tag_replace); i++) { const char *from = webvtt_tag_replace[i].from; const size_t len = strlen(from); - if (!strncmp(p, from, len)) { + if (pend - p >= len && !strncmp(p, from, len)) { av_bprintf(buf, "%s", webvtt_tag_replace[i].to); p += len; again = 1; break; } } - if (!*p) + if (p == pend || !*p) break; if (again) { @@ -89,7 +89,7 @@ static int webvtt_decode_frame(AVCodecContext *avctx, AVBPrint buf; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); - if (ptr && avpkt->size > 0 && !webvtt_event_to_ass(&buf, ptr)) + if (ptr && avpkt->size > 0 && !webvtt_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)