From patchwork Sat Mar 13 21:33:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 26381 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 C3FF6449FF1 for ; Sat, 13 Mar 2021 23:34:35 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A812668AC9C; Sat, 13 Mar 2021 23:34: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 E1CF268AC4A for ; Sat, 13 Mar 2021 23:34:28 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id BB775E51B0; Sat, 13 Mar 2021 22:34: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 GXDjUVUZlQ5b; Sat, 13 Mar 2021 22:33:56 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3A25AE50E8; Sat, 13 Mar 2021 22:33:56 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Mar 2021 22:33:39 +0100 Message-Id: <20210313213345.3268-2-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 2/8] avcodec/samidec: 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/samidec.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libavcodec/samidec.c b/libavcodec/samidec.c index e32f238c62..f03b5db958 100644 --- a/libavcodec/samidec.c +++ b/libavcodec/samidec.c @@ -38,12 +38,12 @@ typedef struct { int readorder; } SAMIContext; -static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src) +static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src, size_t size) { SAMIContext *sami = avctx->priv_data; int ret = 0; char *tag = NULL; - char *dupsrc = av_strdup(src); + char *dupsrc = av_strndup(src, size); char *p = dupsrc; AVBPrint *dst_content = &sami->encoded_content; AVBPrint *dst_source = &sami->encoded_source; @@ -135,11 +135,10 @@ static int sami_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *avpkt) { AVSubtitle *sub = data; - const char *ptr = avpkt->data; SAMIContext *sami = avctx->priv_data; - if (ptr && avpkt->size > 0) { - int ret = sami_paragraph_to_ass(avctx, ptr); + if (avpkt->data && avpkt->size > 0) { + int ret = sami_paragraph_to_ass(avctx, avpkt->data, avpkt->size); if (ret < 0) return ret; // TODO: pass escaped sami->encoded_source.str as source