From patchwork Sat May 6 00:10:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 3587 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.3.129 with SMTP id 123csp471146vsd; Fri, 5 May 2017 17:11:13 -0700 (PDT) X-Received: by 10.28.150.86 with SMTP id y83mr6871619wmd.46.1494029473694; Fri, 05 May 2017 17:11:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494029473; cv=none; d=google.com; s=arc-20160816; b=jmckIfIQgHtlwFEBN4ZOvJinQ3qsd00FmDOJd2Yz5vRagIvQAKPjfkaued+N4TqAFA pUfhGDT9ShM/WLjhVKj049rkjgfd3kueY5aAxGCDrv37AFzLShZKbobivEzFgZj66AyC vCzCI7FpNMrJj0HGcOL5eyVxKNSXdrQR9JXM2NvUsUtytpwLwPlp50dLClKv+g4cMIVe mxVnpoKgOv0g+P1WMHpIn8Rf9x3LbGSRkjgVumaU8T1aJZ3MY9oJdgHjwIouig5XHMtG wTztx44AWySKm0d9SP1Um2UTZONvkq5UzjK119a/dZipG0ih/xqGsG5yW1fo3HbG+bd0 Vj7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=V1QgjqK+ouSsTD+jLHnAhkZ0g9r0cGpGCLNQ1Wvev9M=; b=IG5Xe5UGCU8lAKLKNu8y89rOPhQarH/QtFnjlcfE7RlE0+QmYbuKniLYJ1eZN1zm74 1uATzNaiLR6hx47oErducOVE9/uyR94Pww4f1k7AcwHPg6pNUUp8XekIOhTjDit7yJ92 IvExWo4e8dm/2v2KQjBtP3eMwb+Xq4V0PT0AGinRxT3b1QwKsYVntpWAzpVNfBHfGPoS /g2Yc9QLUmBL22k2+YpB23i+9bX6o5j/32heE2gtC9RgUSiQuQLYK1AfK3ylRpMzDHYJ gRqSkS7tJfntR0T/xgg2nFmQDQMdJo/0wgnG9H5hGOzhf7FiyrlAawyfxq1BWCaepZpF 3bxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t13si6298536wme.42.2017.05.05.17.11.13; Fri, 05 May 2017 17:11:13 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D4CB4689A36; Sat, 6 May 2017 03:11:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe02-3.mx.upcmail.net (vie01a-qmta-pe02-3.mx.upcmail.net [62.179.121.183]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 53D286899EB for ; Sat, 6 May 2017 03:10:56 +0300 (EEST) Received: from [172.31.218.31] (helo=vie01a-dmta-pe01-1.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1d6nJN-0004YH-1P for ffmpeg-devel@ffmpeg.org; Sat, 06 May 2017 02:11:01 +0200 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe01.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1d6nJH-00017i-BU for ffmpeg-devel@ffmpeg.org; Sat, 06 May 2017 02:10:55 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id GoAr1v0050S5wYM01oAsz2; Sat, 06 May 2017 02:10:52 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 6 May 2017 02:10:47 +0200 Message-Id: <20170506001050.23234-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/htmlsubtitles: Check for string truncation and return error 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes out of array access Fixes: 1354/clusterfuzz-testcase-minimized-5520132195483648 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/htmlsubtitles.c | 12 +++++++++--- libavcodec/htmlsubtitles.h | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libavcodec/htmlsubtitles.c b/libavcodec/htmlsubtitles.c index 8b57febd26..16295daa0c 100644 --- a/libavcodec/htmlsubtitles.c +++ b/libavcodec/htmlsubtitles.c @@ -46,11 +46,12 @@ typedef struct SrtStack { static void rstrip_spaces_buf(AVBPrint *buf) { - while (buf->len > 0 && buf->str[buf->len - 1] == ' ') - buf->str[--buf->len] = 0; + if (av_bprint_is_complete(buf)) + while (buf->len > 0 && buf->str[buf->len - 1] == ' ') + buf->str[--buf->len] = 0; } -void ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in) +int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in) { char *param, buffer[128], tmp[128]; int len, tag_close, sptr = 1, line_start = 1, an = 0, end = 0; @@ -171,8 +172,13 @@ void ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in) line_start = 0; } + if (!av_bprint_is_complete(dst)) + return AVERROR(ENOMEM); + while (dst->len >= 2 && !strncmp(&dst->str[dst->len - 2], "\\N", 2)) dst->len -= 2; dst->str[dst->len] = 0; rstrip_spaces_buf(dst); + + return 0; } diff --git a/libavcodec/htmlsubtitles.h b/libavcodec/htmlsubtitles.h index e10cdda241..f3a8ef5d8b 100644 --- a/libavcodec/htmlsubtitles.h +++ b/libavcodec/htmlsubtitles.h @@ -23,6 +23,6 @@ #include "libavutil/bprint.h" -void ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in); +int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in); #endif /* AVCODEC_HTMLSUBTITLES_H */