From patchwork Tue Dec 7 23:24:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 32115 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp6946847iog; Tue, 7 Dec 2021 15:25:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2hKhi/uhIvZeXFOKQK5NTyJhAYnMJ1aH7BNLVDg3qQ05XTexRF868P9VkZufaFDmMUtSp X-Received: by 2002:a05:6402:3da:: with SMTP id t26mr14016612edw.232.1638919536388; Tue, 07 Dec 2021 15:25:36 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m17si1767813edj.224.2021.12.07.15.25.36; Tue, 07 Dec 2021 15:25:36 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=KAlQIGVW; arc=fail (body hash mismatch); 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0550768ADE7; Wed, 8 Dec 2021 01:25:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (unknown [40.92.89.38]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8D68268921B for ; Wed, 8 Dec 2021 01:25:18 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ghvBV2JbgoFEUfs5dXvz9dFVU0/BonbITE/yfk09IS1VzK+ODsmmvdMb35ITVkQyndygsbPuoyJZVRterTbeiRM2ynj8JxP+eMW93d00hO4SL9tDFTo5Edvvek1BzAfbtExFIUe6BxEvakOLHIf+uRglnGvCFVKkl39wiuhL/EbLjs/9qp3MdBSczUqLZAuibaxQU+So8HSyvSrWr4mJFgc8hO4VvaVwp8cKBv1AOhec0tslvwd9j6AGDuTFgdEGsSZLeTZHSEPanEzhMQHUCPZz4fw5YtZ9LgD+W4leo18WfU8vOvkF+fcl72eGOckLet0p+nJ0QmRuPzjMOEnGew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ISg0kpsgwaGJjdZlBcdUmZmKlBc/tq4wuy7XnRgB8Jk=; b=j63Ixtme9QOrt4DwGJ2wgZotvVbg7XI90zYgvwnPU6jgYgh8MExYTY1ofQe162wJlH5zsQkcEmn3bGB1g6HWoDemdgiJ7VdOrgOuMxoIk2OGaC63DMZss2FJ3kbqELrFJut47kvCg1zh2dFrBTBTuLNFVeHHoiyhQUAB57H0hrrpfZg0KjhtdxU+7j+kJ3PHbURpnQJ2U+sJsUgk+WkhVtgQlXEom0vNUIxAYjJUMcn1B7w2OJk+HWpXKCUplDNbHyV4Qt2Zjd8+a5Qo2shCydmkRvYcee3Uyw/qsnyp5K+jHEGaRGdsxYZMAIxE8TlaOCgHO9dFymrkl/++HmeVeA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ISg0kpsgwaGJjdZlBcdUmZmKlBc/tq4wuy7XnRgB8Jk=; b=KAlQIGVWXN3SVq+GgP90+pVBq7lkXbhhG9vm12242RmRVYGxY+dsNqmp8CMeDdv9Cx5qtPthb0tbNcZuqcFUDtBY2FlkgfppTMrZLDFiHV1efYlKV4OwAE+sKz7Wg3xbwFAyi4mZT1uU8VgBtYUeeRvkDoFPraUKmxC8WZanzO5sfGTnHhV1QWgEBx1AjxOIO1aj81bJOBKIijiWzE7jAxsfHUkMlGIOtP8xg1jYSVeBodlWyizeiw6a8F3vEDUtwugyKkjVwddw/tH4DaP6tZ+mx0GnCh7SEb2aTgVdWrlGGcVC+u/8Wr8swRrgpmUtM9+s+25kRyRxt0ErrgCjrg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR0302MB3480.eurprd03.prod.outlook.com (2603:10a6:209:19::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11; Tue, 7 Dec 2021 23:25:14 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%4]) with mapi id 15.20.4755.024; Tue, 7 Dec 2021 23:25:14 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 Dec 2021 00:24:59 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [EA4rKOXOru4n1scKR+1GaVTFmSBZCIiT] X-ClientProxiedBy: AM6P192CA0034.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::47) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211207232459.483893-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AM6P192CA0034.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11 via Frontend Transport; Tue, 7 Dec 2021 23:25:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d6368e85-c01d-45ed-46cc-08d9b9d8d21f X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UL+8t5iTwQUa9bnNW0N/TvNnHDaZ78mrC5XY1Jn6sOWBNsyZU1Wu6GmCJk8c+3E+cso1x8nasEiqCScZZ/yl+jUOoTfsYBafTul/S5DVVBTPPMo3h736irPI4hnhjpmIgmtULmB8EeT0Q9WSPSc3f2aHrxZfTYsCmvpU5j3VtXJbM8g99nrnucTjBYunGUTlIfxb37uvQ7kRIIRLS/fAIwzJo9vbkltUAq2++gzVSm2tEc8YUvIMkeiO7w5ibfRXQ6HS/RVe8+tlICWVDtN2xQIITv5xJIywoYkBwXqx3nS//zjbG0AMWV7SFtFOU+V3rTdHE/fQadpyqr5IcIBBPfcT+a0hRElSgHaFCWeGtu/nGdEtxLbfFC+JNQ+01PbD6DCcXWISKqaAxjK3dmCy7e8zortKNMDTbdi+eYWG26Naxj69/5mS5Tzy0nYJGhgAb93Zkab/pi41BUO5LoS/lB4KmCwoJ7PpqX60ktMsDSqHRTuqv46hrAtAKLlQJRjD3gNEEIgTxFJ+Wod7zwAJ6smSJGkVJen9xXa61wQBNl0zCzSVtzK5M9bjPg3WitL6RbIsyiWWZ23cokBs1K1GtxLVKPxfbhx8f4/mGXPrsVM4zAfhGtI0uy42FWK99OhB+e7Xp4T1h0S2ZTuWDjmdj/OL0tO3rrQjCL30lJgzAYabBibt6IDwFWWSeG5AoK8EVWrZrbj4IB0yg== X-MS-TrafficTypeDiagnostic: AM6PR0302MB3480:EE_ X-Microsoft-Antispam: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jNyvfzPF6n13vJmPzBunNYqnsGpbu5HDqt1//V6Gd7TjFvqwhvR7qlX6G+op/Zqa/IivkJGXwrATS+AwgQjeIm4hvIFD/Vn5UCwBXt3vDfH2YEhJIYM4hQ+hzhS0vOhOIVJrr6BFwApJpfmyI3bpcPG3i/z0B0Fe0Jq0ADjXDcNZcrwoUc27ZaAhAP4zg3eXz1cQARy2W3I7mJGUOxBX4hqUFXglplpvYbe8u4jhadtvnSCdgsQL4zEwbOcf+eO/KJxr27WzP2PYSleD1kXTm3zjuxJqCXvYtykV9omTnqymgK7ZbIbNf7ozhnUe6yLKzSfOthQL/4Va3kqQ04GO3ygfpKWeJjl/wCbtT7MIESSAWdHE3v7y504/A89Um7giUfJRFNr8VoL/jRZo9oKhOCx3GanLK7aEMOnYcZVROh2nDpJ3iTwFjNVo7IOfYLt2owowJfsKJ23OAt0DKdKy0dTonbbeWi9fUaOq3lQ1O7hiVaJVoPugP9ZwBk3/CJnuTVYUQ6CkSsBk/dkgaUwEAZsp6BDJPCfOF6MKqTfq39bw67qOCQP4BtSxR5iUOhQtq3J7XIZq5t35L4llKnWg3AZw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6368e85-c01d-45ed-46cc-08d9b9d8d21f X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2021 23:25:14.0850 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0302MB3480 Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/movtextdec: Sanitize style entries X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: VQ8aCCRXaXGV There are three types of style entries which are redundant: a) Entries with length zero. They are already discarded. b) Entries that are equivalent to the default style: They can be safely discarded. c) Entries that are equivalent to the immediately preceding style if the start of the current style coincides with the end of the preceding style. In this case the styles can be merged. This commit implements discarding/merging in cases b) and c). This fixes ticket #9548. In said ticket each packet contained exactly one style entry that covered the complete packet with the exception of the last character (probably created by a tool that didn't know that the style's end is exclusive). Said style coincided with the default style, leading to a superfluous reset, which is now gone. Signed-off-by: Andreas Rheinhardt --- libavcodec/movtextdec.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c index c50626c0b5..b0c54bf1d0 100644 --- a/libavcodec/movtextdec.c +++ b/libavcodec/movtextdec.c @@ -263,6 +263,14 @@ static int decode_hclr(const uint8_t *tsmb, MovTextContext *m, const AVPacket *a return 0; } +static int styles_equivalent(const StyleBox *a, const StyleBox *b) +{ +#define CMP(field) a->field == b->field + return CMP(bold) && CMP(italic) && CMP(underline) && CMP(color) && + CMP(alpha) && CMP(fontsize) && CMP(font_id); +#undef CMP +} + static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket *avpkt) { int i; @@ -299,6 +307,19 @@ static int decode_styl(const uint8_t *tsmb, MovTextContext *m, const AVPacket *a } mov_text_parse_style_record(style, &tsmb); + if (styles_equivalent(style, &m->d.style)) { + /* Skip this style as it is equivalent to the default style */ + m->style_entries--; + i--; + continue; + } else if (i && style->start == style[-1].end && + styles_equivalent(style, &style[-1])) { + /* Merge the two adjacent styles */ + style[-1].end = style->end; + m->style_entries--; + i--; + continue; + } } return 0; }