From patchwork Sat Mar 13 21:33:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 26384 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 C94EC44A6CC for ; Sat, 13 Mar 2021 23:35:33 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A7A3E68AD0C; Sat, 13 Mar 2021 23:35:33 +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 F238468AC9A for ; Sat, 13 Mar 2021 23:35:26 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C2BE6E51B4; Sat, 13 Mar 2021 22:35:26 +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 axHva172zP37; Sat, 13 Mar 2021 22:34:56 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 0B3EDE50EF; Sat, 13 Mar 2021 22:34:08 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Mar 2021 22:33:42 +0100 Message-Id: <20210313213345.3268-5-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 5/8] avcodec/subviewerdec: 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/subviewerdec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/subviewerdec.c b/libavcodec/subviewerdec.c index 805c7dd547..1016ac7ada 100644 --- a/libavcodec/subviewerdec.c +++ b/libavcodec/subviewerdec.c @@ -28,10 +28,10 @@ #include "ass.h" #include "libavutil/bprint.h" -static int subviewer_event_to_ass(AVBPrint *buf, const char *p) +static int subviewer_event_to_ass(AVBPrint *buf, const char *p, const char *pend) { - while (*p) { - if (!strncmp(p, "[br]", 4)) { + while (p < pend && *p) { + if (pend - p >= 4 && !strncmp(p, "[br]", 4)) { av_bprintf(buf, "\\N"); p += 4; } else { @@ -56,7 +56,7 @@ static int subviewer_decode_frame(AVCodecContext *avctx, AVBPrint buf; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); - if (ptr && avpkt->size > 0 && !subviewer_event_to_ass(&buf, ptr)) + if (ptr && avpkt->size > 0 && !subviewer_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)