From patchwork Sat Jul 1 22:09:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 4183 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp7435889vsb; Sat, 1 Jul 2017 15:10:04 -0700 (PDT) X-Received: by 10.223.129.6 with SMTP id 6mr17482993wrm.23.1498947004425; Sat, 01 Jul 2017 15:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498947004; cv=none; d=google.com; s=arc-20160816; b=jr6iQCW/oIquSEHkTHUd7Bn5ogN5vWsn4DTP4bMUN+gpCijAxtf9dpOfdNV9nJz04m H7TobkeTPauQ17HJ8hU3cZ9VVYpMU6P3o4Ak8NVAdU3i9ZiOG0ZlsL9rz5fvHiQUmgG3 gBbRSFb5IqOJP0N7q2/iHzlKcCzKfN4S5x69fkTfV5RubcAmhqrOp0IQo3h1uLrjEKq1 ZBZlle50yArrXUBxqJ65zCaziggn+HN/qEhpM5sFiLx6+jNWK3TwvQ0d3BymX739Sa2/ obz1DC3Jx+ZJ0h19V+qY7FasMMuSWwdoozXv58S1sj7GsAhn0KdMAi27fZlTvrjg4O+e DHUQ== 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=QgLVyBrySDKfOlpv4HYG9qhWZ6dY8dgQBcWkiMuRy4k=; b=pEOjIounO111Gi9ZmyKiNlrC1nBklqPy2bag0dR0oMkEiB6P10WgDmlspRUB3oy3fL jMgg1xwpfhKrFJJnVjbO2kZoeeovNoEeTx8k737dvvnNMabiBp0KShOvkJcdnExFIf3N WDN6NOycCSAXnJvFZb+IIyfy2fo+GQ1ezCmNHNCMs3yPUGoTOoYzw+MF2KV29u1I/UTQ bkh2p1iG2kops9zFmlXhVAGJSPSZK9tuiJEzC1nxhoIO8U0IZhN6Ie+Z8QdoZ+uIz9Dq +gKHGJR8/DfFaPigcSm7jm2owC+d3ECcQPo8MFDS1jJEJPunnXpCqUxSeAqgfNLR+lWi 3JtA== 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 h188si12127641wmf.140.2017.07.01.15.10.03; Sat, 01 Jul 2017 15:10:04 -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 CE4B3680AB3; Sun, 2 Jul 2017 01:09:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe03-1.mx.upcmail.net (vie01a-dmta-pe03-1.mx.upcmail.net [62.179.121.160]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F0A38680934 for ; Sun, 2 Jul 2017 01:09:52 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe03.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1dRQaO-0005wI-Uq for ffmpeg-devel@ffmpeg.org; Sun, 02 Jul 2017 00:09:52 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id fa9i1v00d0S5wYM01a9j0u; Sun, 02 Jul 2017 00:09:43 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 2 Jul 2017 00:09:42 +0200 Message-Id: <20170701220942.20818-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.13.0 Subject: [FFmpeg-devel] [PATCH] avcodec/htmlsubtitles: Be a bit more picky on syntax 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" This reduces the number of strstr() calls per byte This diasalows empty tags like '< >' as well as '<' in tags like '' Fixes timeout Fixes: 1817/clusterfuzz-testcase-minimized-5104230530547712 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/htmlsubtitles.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/htmlsubtitles.c b/libavcodec/htmlsubtitles.c index be5c9316ca..67abc94085 100644 --- a/libavcodec/htmlsubtitles.c +++ b/libavcodec/htmlsubtitles.c @@ -110,13 +110,13 @@ int ff_htmlmarkup_to_ass(void *log_ctx, AVBPrint *dst, const char *in) case '<': tag_close = in[1] == '/'; len = 0; - if (sscanf(in+tag_close+1, "%127[^>]>%n", buffer, &len) >= 1 && len > 0) { + if (sscanf(in+tag_close+1, "%127[^<>]>%n", buffer, &len) >= 1 && len > 0) { const char *tagname = buffer; while (*tagname == ' ') tagname++; if ((param = strchr(tagname, ' '))) *param++ = 0; - if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) || + if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack) && *tagname) || ( tag_close && sptr > 0 && !strcmp(stack[sptr-1].tag, tagname))) { int i, j, unknown = 0; in += len + tag_close;