From patchwork Sat Mar 13 21:33:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 26380 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 B94B2449FF1 for ; Sat, 13 Mar 2021 23:34:33 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 982C868AC66; Sat, 13 Mar 2021 23:34: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 0DADA68AC4A for ; Sat, 13 Mar 2021 23:34:27 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id DEC98E51B4; Sat, 13 Mar 2021 22:34: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 mk976POZ_QOA; Sat, 13 Mar 2021 22:33:50 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 2D20BE50B7; Sat, 13 Mar 2021 22:33:50 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Mar 2021 22:33:38 +0100 Message-Id: <20210313213345.3268-1-cus@passwd.hu> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/8] avcodec/assdec: 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/assdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c index f0b1069cd2..655fc1365c 100644 --- a/libavcodec/assdec.c +++ b/libavcodec/assdec.c @@ -54,7 +54,7 @@ static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, return AVERROR(ENOMEM); sub->num_rects = 1; sub->rects[0]->type = SUBTITLE_ASS; - sub->rects[0]->ass = av_strdup(avpkt->data); + sub->rects[0]->ass = av_strndup(avpkt->data, avpkt->size); if (!sub->rects[0]->ass) return AVERROR(ENOMEM); *got_sub_ptr = 1; 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 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) From patchwork Sat Mar 13 21:33:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 26383 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 F1D7E44A6CC for ; Sat, 13 Mar 2021 23:35:05 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D8D1368ACEF; Sat, 13 Mar 2021 23:35:05 +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 ED4E268ACE8 for ; Sat, 13 Mar 2021 23:34:58 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A6E00E50EC; Sat, 13 Mar 2021 22:34:58 +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 yy38VyliJTof; Sat, 13 Mar 2021 22:34:28 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 6A516E50EE; Sat, 13 Mar 2021 22:34:04 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Mar 2021 22:33:41 +0100 Message-Id: <20210313213345.3268-4-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 4/8] avcodec/realtextdec: 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/realtextdec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/realtextdec.c b/libavcodec/realtextdec.c index 5084781123..bdd9659235 100644 --- a/libavcodec/realtextdec.c +++ b/libavcodec/realtextdec.c @@ -29,11 +29,11 @@ #include "libavutil/avstring.h" #include "libavutil/bprint.h" -static int rt_event_to_ass(AVBPrint *buf, const char *p) +static int rt_event_to_ass(AVBPrint *buf, const char *p, const char *pend) { int prev_chr_is_space = 1; - while (*p) { + while (p < pend && *p) { if (*p != '<') { if (!av_isspace(*p)) av_bprint_chars(buf, *p, 1); @@ -41,7 +41,7 @@ static int rt_event_to_ass(AVBPrint *buf, const char *p) av_bprint_chars(buf, ' ', 1); prev_chr_is_space = av_isspace(*p); } else { - const char *end = strchr(p, '>'); + const char *end = av_strnstr(p, ">", pend - p); if (!end) break; if (!av_strncasecmp(p, "
", 5) || @@ -65,7 +65,7 @@ static int realtext_decode_frame(AVCodecContext *avctx, AVBPrint buf; av_bprint_init(&buf, 0, 4096); - if (ptr && avpkt->size > 0 && !rt_event_to_ass(&buf, ptr)) + if (ptr && avpkt->size > 0 && !rt_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) 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) 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) 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; From patchwork Sat Mar 13 21:33:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 26387 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 DB9E544A6CC for ; Sat, 13 Mar 2021 23:36:06 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C19B968AD1C; Sat, 13 Mar 2021 23:36:06 +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 D69E668ACF2 for ; Sat, 13 Mar 2021 23:35:59 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C2A86E50F1; Sat, 13 Mar 2021 22:35:59 +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 1DmXkJvtvsij; Sat, 13 Mar 2021 22:35:28 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9163DE50F2; Sat, 13 Mar 2021 22:34:22 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Mar 2021 22:33:45 +0100 Message-Id: <20210313213345.3268-8-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 8/8] avformat/assenc: 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 --- libavformat/assenc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libavformat/assenc.c b/libavformat/assenc.c index 68c3396e5a..265b5996ac 100644 --- a/libavformat/assenc.c +++ b/libavformat/assenc.c @@ -156,16 +156,23 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) ASSContext *ass = s->priv_data; long int layer; - char *p = pkt->data; + char *dup = av_strndup(pkt->data, pkt->size); + char *p = dup; int64_t start = pkt->pts; int64_t end = start + pkt->duration; int hh1, mm1, ss1, ms1; int hh2, mm2, ss2, ms2; - DialogueLine *dialogue = av_mallocz(sizeof(*dialogue)); + DialogueLine *dialogue; - if (!dialogue) + if (!dup) return AVERROR(ENOMEM); + dialogue = av_mallocz(sizeof(*dialogue)); + if (!dialogue) { + av_free(dup); + return AVERROR(ENOMEM); + } + dialogue->readorder = strtol(p, &p, 10); if (dialogue->readorder < ass->expected_readorder) av_log(s, AV_LOG_WARNING, "Unexpected ReadOrder %d\n", @@ -189,6 +196,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) dialogue->line = av_asprintf("%s%ld,%d:%02d:%02d.%02d,%d:%02d:%02d.%02d,%s", ass->ssa_mode ? "Marked=" : "", layer, hh1, mm1, ss1, ms1, hh2, mm2, ss2, ms2, p); + av_free(dup); + if (!dialogue->line) { av_free(dialogue); return AVERROR(ENOMEM);