From patchwork Sat Mar 13 21:33:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 26382 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 D6221449FF1 for ; Sat, 13 Mar 2021 23:35:03 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B4FE968ACC9; Sat, 13 Mar 2021 23:35:03 +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 D9CCA68AB0E for ; Sat, 13 Mar 2021 23:34:56 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C4F2DE51B4; Sat, 13 Mar 2021 22:34:56 +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 YQe3U7fqWR_c; Sat, 13 Mar 2021 22:34:27 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D3412E50EC; Sat, 13 Mar 2021 22:34:00 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Mar 2021 22:33:40 +0100 Message-Id: <20210313213345.3268-3-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 3/8] avcodec/mpl2dec: 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/mpl2dec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/mpl2dec.c b/libavcodec/mpl2dec.c index 409e4b3708..efeecb0d64 100644 --- a/libavcodec/mpl2dec.c +++ b/libavcodec/mpl2dec.c @@ -29,15 +29,15 @@ #include "ass.h" #include "libavutil/bprint.h" -static int mpl2_event_to_ass(AVBPrint *buf, const char *p) +static int mpl2_event_to_ass(AVBPrint *buf, const char *p, const char *pend) { if (*p == ' ') p++; - while (*p) { + while (p < pend && *p) { int got_style = 0; - while (*p && strchr("/\\_", *p)) { + while (p < pend && *p && strchr("/\\_", *p)) { if (*p == '/') av_bprintf(buf, "{\\i1}"); else if (*p == '\\') av_bprintf(buf, "{\\b1}"); else if (*p == '_') av_bprintf(buf, "{\\u1}"); @@ -45,13 +45,13 @@ static int mpl2_event_to_ass(AVBPrint *buf, const char *p) p++; } - while (*p && *p != '|') { + while (p < pend && *p && *p != '|') { if (*p != '\r' && *p != '\n') av_bprint_chars(buf, *p, 1); p++; } - if (*p == '|') { + if (p < pend && *p == '|') { if (got_style) av_bprintf(buf, "{\\r}"); av_bprintf(buf, "\\N"); @@ -72,7 +72,7 @@ static int mpl2_decode_frame(AVCodecContext *avctx, void *data, FFASSDecoderContext *s = avctx->priv_data; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); - if (ptr && avpkt->size > 0 && *ptr && !mpl2_event_to_ass(&buf, ptr)) + if (ptr && avpkt->size > 0 && *ptr && !mpl2_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)