From patchwork Sat Mar 13 21:33:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 26386 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 D7BB744A6CC for ; Sat, 13 Mar 2021 23:36:03 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BC86168ACDC; Sat, 13 Mar 2021 23:36: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 52A3868ACDC for ; Sat, 13 Mar 2021 23:35:57 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3F463E51B4; Sat, 13 Mar 2021 22:35:57 +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 wLLiseTf89pd; Sat, 13 Mar 2021 22:35:26 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 484CBE50F1; Sat, 13 Mar 2021 22:34:20 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Mar 2021 22:33:44 +0100 Message-Id: <20210313213345.3268-7-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 7/8] avcodec/srtdec: 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/srtdec.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libavcodec/srtdec.c b/libavcodec/srtdec.c index 98f84ac673..37fb0d3173 100644 --- a/libavcodec/srtdec.c +++ b/libavcodec/srtdec.c @@ -62,6 +62,7 @@ static int srt_decode_frame(AVCodecContext *avctx, buffer_size_t size; const uint8_t *p = av_packet_get_side_data(avpkt, AV_PKT_DATA_SUBTITLE_POSITION, &size); FFASSDecoderContext *s = avctx->priv_data; + char *dup; if (p && size == 16) { x1 = AV_RL32(p ); @@ -73,12 +74,17 @@ static int srt_decode_frame(AVCodecContext *avctx, if (avpkt->size <= 0) return avpkt->size; + dup = av_strndup(avpkt->data, avpkt->size); + if (!dup) + return AVERROR(ENOMEM); + av_bprint_init(&buffer, 0, AV_BPRINT_SIZE_UNLIMITED); - ret = srt_to_ass(avctx, &buffer, avpkt->data, x1, y1, x2, y2); + ret = srt_to_ass(avctx, &buffer, dup, x1, y1, x2, y2); if (ret >= 0) ret = ff_ass_add_rect(sub, buffer.str, s->readorder++, 0, NULL, NULL); av_bprint_finalize(&buffer, NULL); + av_free(dup); if (ret < 0) return ret;