From patchwork Sat Oct 17 07:37:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23028 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 BA22F44A037 for ; Sat, 17 Oct 2020 10:37:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 92AD468B8AF; Sat, 17 Oct 2020 10:37:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 120D368B5C2 for ; Sat, 17 Oct 2020 10:37:53 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id s9so5889959wro.8 for ; Sat, 17 Oct 2020 00:37:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QYeMuu6BXS8jJW21Nl47vih+VrDFy8ajMEs+BD8Q6UM=; b=rHhPNTqXkJjvasLHeC7aOG+nf1kFCGu9UHeQ9CPId8iVj1AZTKyNJgRVAKPHgB8QvP hGNpWhPvKbhUCuS+CgcJ3jC8LOFwv78lknagq2PgeY9VYbtfRoYYOiPv1FyXbwL+E+Hc Bgvg5Wspww7fidCjt0PeyTl93Z2JZHt2lmLkIhVNhuvxnMtr07H0JoS7O7ZnI/OeCOeA vc6jFY5PJ02g/K+ezWsysHdc1SBPMEsK3QXrEdgtakJtG2KnXVgRbwCEcmg1QIQ+0nLp E6qWm4mgaqntpG4LYp8AKkbFRbKVqgRxforA9P67W19kjrPo1bGfwPzQOF2ZH5rMUg8x nXmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=QYeMuu6BXS8jJW21Nl47vih+VrDFy8ajMEs+BD8Q6UM=; b=tiojbYhJwhgrHSyVw9oFQtTfL0pf+Tf24f2TRmAK1zWFIDc84gxREJadaC0y6yQgjG X8fzlQuwu95dKLrw+NTgLi+Y4YmfiRL2cCufhf+9ESL2AGqbw7f5vXVo5jAEaQEm2r4f R/5MA6P/LFdwuBvWF9pmgX1fpPc4GyTyvXtm53GokfgrfN7elouD1+bevw+zv1fklQdm XaeZSyCwOKP2EvLd8JlpnwGT3IcYFMWca+npbtVvAAmGR0IdzTZEmWkpWrBi5w+GKEbV wsxBmdNplFfDYQumxLXTtgT1333SNzpNOT3KCzQXcMuSyngBKTgFWx5GgqEQosUtg2nw K+bA== X-Gm-Message-State: AOAM532Wqoe7h2XQKwfRhDqupr/k/zR3O19WNETPO53H/1k1qkKr1+UL 8iZGv9PjgZGOHNbPigKMhQPGheS25cQ= X-Google-Smtp-Source: ABdhPJzU3UAoD0WJvMp+K2qYhB0yg2tKyJ9ckY1EvAssc2eADYeaVrIG9XTSFQRrCp5PMKEA4wqmkQ== X-Received: by 2002:a5d:6944:: with SMTP id r4mr8758522wrw.151.1602920272036; Sat, 17 Oct 2020 00:37:52 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id 24sm5946553wmg.8.2020.10.17.00.37.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 00:37:51 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Oct 2020 09:37:38 +0200 Message-Id: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/8] avcodec/movtextenc: Fix potential use of uninitialized value 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Background colour was never initialized if no style was available. Use a sane default of zero (i.e. completely transparent). Fixes Coverity issue #1461471. Signed-off-by: Andreas Rheinhardt --- No change for this patch since last time; I am just resending all because I have added a few patches that I intend to backport and that therefore should be applied before "Simplify writing to AVBPrint". libavcodec/movtextenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 5f60b8db61..11db240ab7 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -205,7 +205,7 @@ static int encode_sample_description(AVCodecContext *avctx) ASS *ass; ASSStyle *style; int i, j; - uint32_t tsmb_size, tsmb_type, back_color, style_color; + uint32_t tsmb_size, tsmb_type, back_color = 0, style_color; uint16_t style_start, style_end, fontID, count; int font_names_total_len = 0; MovTextContext *s = avctx->priv_data; From patchwork Sat Oct 17 07:37:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23030 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 75AAB44A23D for ; Sat, 17 Oct 2020 10:38:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5686A68B61C; Sat, 17 Oct 2020 10:38:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 653CF68B61C for ; Sat, 17 Oct 2020 10:38:22 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id n15so5940906wrq.2 for ; Sat, 17 Oct 2020 00:38:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QgRZgxdAU0ydGrx1r/w/XSVAzW6kkilvG63wT3DZV0Q=; b=bfYjayFUCH7A8VdVN0vpvOV3YH+FSEkjI4uXFFj0MYoA43UK4Klw8WJZUMdFu4dDXD DaoSvBgfIfAHXBkSxzKSlnGNcEGZnKutD08p2GAf+UL2Bc2beMNnOQBTZEM4uw8dIaLw kV5SCVwWEvqnBOCsB8EA2PmuC3LQHNUAD/aJWJ+hC4KhkrDQ6s32rOhWJnA+9IYbhb+w bVfGqayxRKhFjYGZ9SjyVgBEuDM7eu31aGEMbuVdJyafyFP4JnuGYMOfXAm8SnIb+7+m yEbkIU0n66WYadnHMyjTSGHiH06DF09xYrLdI3MbJhtKdF+DUHUfOPb82zm/egVAJDbG eoqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QgRZgxdAU0ydGrx1r/w/XSVAzW6kkilvG63wT3DZV0Q=; b=ecNS/Vhvz0TC1W3VtvZFpoLPquPWdkX6LDDH7dHMYKC5QR0wI9NM+4+h2vwegge1fT fRDY3riCJRcFi5foqAJTxF32eiHCGLpmai8UHjvL3xcSlg/CVOGfzROpt8Q5hFP5a/XE O9eNMTbOFFrCrN3dkSCPfEm8rJjzgxVdjDisMEE+Q7x3kybThwgCyN6aZYx0W5MV+yTc uKvFA0Tua4GUXmFpjdvuKrvd/UEk6XIf3YWbgjABEwLkCY5pBrAPrgSlWCFlSsPYXI+x v9JDe4G9FQCXQ4px/OrePfN6e99lHbW37+8paCHRmRue+vKzSFcwZEmPpDbIvHFss6Ux NjWQ== X-Gm-Message-State: AOAM531QWX4InGCsqW9XoB9F5GTLg93SZIMRGfF9b7BgxsxqYrZCQVNt m3ISy9Yix2nKGFmA4KuOcGA6/MjzFr4= X-Google-Smtp-Source: ABdhPJxqJR8t6NoX+jIarh802gd1oxDeOnG++agHQSgQrYGblGkuByZPltDzEiinnvsrR5aJXR8jFQ== X-Received: by 2002:a5d:4141:: with SMTP id c1mr8590033wrq.113.1602920301579; Sat, 17 Oct 2020 00:38:21 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id 24sm5946553wmg.8.2020.10.17.00.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 00:38:20 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Oct 2020 09:37:39 +0200 Message-Id: <20201017073745.403153-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> References: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 2/8] avcodec/movtextenc: Reset array counter after freeing array 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Otherwise the mov_text encoder can segfault when given subtitles with more than one AVSubtitleRect if one of the first nb_rects - 1 rects contained a style attribute. Signed-off-by: Andreas Rheinhardt --- The earlier commit message claimed to be about a muxer in avcodec/movtextdec. I still don't know whether the STYL_BOX flag should be reset or not. libavcodec/movtextenc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 11db240ab7..81e8c2e802 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -102,6 +102,7 @@ static void mov_text_cleanup(MovTextContext *s) av_freep(&s->style_attributes[j]); } av_freep(&s->style_attributes); + s->count = 0; } if (s->style_attributes_temp) { *s->style_attributes_temp = s->d; From patchwork Sat Oct 17 07:37:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23031 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 0EB4544A23D for ; Sat, 17 Oct 2020 10:38:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D831A68B971; Sat, 17 Oct 2020 10:38:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 78C2568B61C for ; Sat, 17 Oct 2020 10:38:23 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id y12so5919358wrp.6 for ; Sat, 17 Oct 2020 00:38:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wM7dPk/HXc1x1Fqgdd5LmhzPTPKB+/nZoreC/6x2STw=; b=aQsqTXRrCNi5GdmperNz7EgBQWqw1nANWLYzFHLYr38C7a1uM9Rsrahyw+37nxiZlX 7QitkUquexo1KsEaYCC8Cd0HGhG4BlD9Z1rL/zYk42I0zdoS/Agcf3k/sgVI/eL2IjAE NX725xiNabvrmv0buoBUVQ//nD7zTUAVoYe/wl95rY4s5oM1r0eclxJ8hn7vpzXZGxZ5 88jhsbsRuhTUhzxsI9dlwsMt1mz1OiKXooHRW3NL7VgSNiLK2hdxGT3P9/1BkeAz56LI uh7+egOu7es2WbvsHXPcG8LksELu4sMCTeAUYdqmijuAY0tKLstVtyR5Lvim6pRht4am tKdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wM7dPk/HXc1x1Fqgdd5LmhzPTPKB+/nZoreC/6x2STw=; b=Pqauysg+o7BySxztxg1xabwYWtUx4aD1BXGi3q+5NBH98+k9zAV1WCA95gsGjmL+G0 b8HkrBCGzqzaEz3gO2Q8Sv0CzKp0Sbx9rJyyKY2+eqd8gC0+OmKOyQKFzgTnqot8YmD/ CTZhJW5MpPzgkaKY6qFCSE4y/geKB0QACKCABSiX0VwjO8O7K1pfjj9E47t3TZ7guKlO B/DD+39WPJVcBRD9C9QqrroDFQRYJbb5JXepas7sLU4zH7xdg7cB8l2vFd0cQSJmXMvH f/OokRkgYpWR/eAwVCX3Q2iELJJM0U013ONGcZt1NmNA7Jia08SdZrRfLGVw8sUOHXD/ vHtw== X-Gm-Message-State: AOAM532pTiQ+KP971YwITCtlxM+YhJdv5WZyPteyB8MRiE1w0HNGxkwU o5Ufl0nFNPM0U2ioeP9zq58RvPwhV60= X-Google-Smtp-Source: ABdhPJwFhBGipgZcPo7EEObMK6xPn1kGZTv+i92rczGR7gQ/mszpyOh4VjvU6rGKpSBDg2P65gzqxQ== X-Received: by 2002:adf:e9c6:: with SMTP id l6mr8677641wrn.257.1602920302453; Sat, 17 Oct 2020 00:38:22 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id 24sm5946553wmg.8.2020.10.17.00.38.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 00:38:21 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Oct 2020 09:37:40 +0200 Message-Id: <20201017073745.403153-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> References: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 3/8] avcodec/movtextenc: Don't presume every style to have a font 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes segfaults in the absence of fonts; this can happen because the file didn't contain any or because the allocation of the font-string failed. Signed-off-by: Andreas Rheinhardt --- libavcodec/movtextenc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 81e8c2e802..dcdbf16e08 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -298,10 +298,14 @@ static int encode_sample_description(AVCodecContext *avctx) // is avaiable in the ASS header if (style && ass->styles_count) { // Find unique font names - av_dynarray_add(&s->fonts, &s->font_count, style->font_name); - font_names_total_len += strlen(style->font_name); + if (style->font_name) { + av_dynarray_add(&s->fonts, &s->font_count, style->font_name); + font_names_total_len += strlen(style->font_name); + } for (i = 0; i < ass->styles_count; i++) { int found = 0; + if (!ass->styles[i].font_name) + continue; for (j = 0; j < s->font_count; j++) { if (!strcmp(s->fonts[j], ass->styles[i].font_name)) { found = 1; From patchwork Sat Oct 17 07:37:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23032 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 3610044A23D for ; Sat, 17 Oct 2020 10:38:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1C63F68B9C2; Sat, 17 Oct 2020 10:38:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AFFD868B94D for ; Sat, 17 Oct 2020 10:38:24 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id x7so5940390wrl.3 for ; Sat, 17 Oct 2020 00:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zMDm9ZChhGIJ3V8EKnZD4+/aRN57c09RWo93R3Cqru0=; b=s1sKu692cX/rLvUlb038OAIgN6rsmKkm7dRUfgxTYZgDiHyOgF8aiesCPbWJVzZKtW pTxyktltHcq7T++VVK7/pq6imN7xfo7Edr/FH2IsRxQwrenk7d0Yeua04uEkDOEX9OFk QkOnGcw8wNQRqbvzBBYQoeACIGBwqvYLOKIj1w8hU2PPaosWGt+n1ArWq+6SB1uVRFkt +IvHaVXLahUpNkCsZ38EFaAOFkU4BlW7gnLyex3887c9hHZC0ogoUyozd5Nxdex5HNow rMJ9ZAk61YvYEGOByDEHFtjc6roSeXH7ORIBFAMA3yiMzf/JMQJq/hW/3lt7xpHjFNc0 rSLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zMDm9ZChhGIJ3V8EKnZD4+/aRN57c09RWo93R3Cqru0=; b=Fm+ZO1Um/BpFw95u7fZDu2R2eJWlRsGwysHjhrx0vQUdhWh8E+e7XpXfxdk7yaBqOe dHLXMevLAxA23zjEM/2EiXMrEDaxO84pR0nH6Q+gIU7Cm1Qap7hOw5izHH+RMboywOy+ l2AIG3nCX5hCGvBJQxaLuBDUFre/AwCNh+5lWps5dBA+VF1X+4LS1o00P3EMNZm0NdoK 0K5bQCdqb+7of7oR49eIPBkqBbE6JLelZkRCwhCTJRd4irHRRT5Mld0rcj+LeoR/OppB hg0/QdYn0+i4iHzYE2JyP4h6xSIBlrcwud2Ept/Z9mlwfo4YKqoNVHIntlsmTpEWwC2E 0UwQ== X-Gm-Message-State: AOAM532ayDL7I1nwHNEsS5KniXuEhUm2ZKjXQdftmXiSeVtKemwP6dbn glJhO0lVDg4Rp+d/jqQtNGIqHnj2hpo= X-Google-Smtp-Source: ABdhPJyZm95fjp9VNZLfcIU/NtiTSGhXclA8M1TFXvv4yfHTgvo+y/1oWEcbQAapkvA+ZL/HQPbBQg== X-Received: by 2002:adf:de89:: with SMTP id w9mr8728452wrl.212.1602920303680; Sat, 17 Oct 2020 00:38:23 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id 24sm5946553wmg.8.2020.10.17.00.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 00:38:22 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Oct 2020 09:37:41 +0200 Message-Id: <20201017073745.403153-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> References: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 4/8] avcodec/movtextenc: Fix memleak on (re)allocation 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Up until now, the mov_text encoder used the dynamic array API for its list of style attributes; it used the (horrible) av_dynarray_add() which works with an array of pointers; on error it frees its array but not the buffers referenced by the pointers said array contains. It also returns no error code, encouraging not to check for errors. These properties imply that this function may only be used if the buffers referenced by the list either need not be freed at all or if they are freed by other means (i.e. if the list contains non-ownership pointers). In this case, the style attributes are owned by the pointers of the dynamic list. Ergo the old style attributes leak on a subsequent reallocation failure. But given that the (re)allocation isn't checked for success, the style attribute intended to be added to the list also leaks because the only pointer to it gets overwritten in the belief that it is now owned by the list. This commit fixes this by switching to av_fast_realloc() and an array containing the styles directly instead of pointers to individually allocated style attributes. The current style attributes are now no longer individually allocated, instead they are part of the context. Furthermore, av_fast_realloc() allows to easily distinguish between valid and allocated elements, thereby allowing to reuse the array (which up until now has always been freed after processing an AVSubtitleRect). Signed-off-by: Andreas Rheinhardt --- The check "s->count + 1 > SIZE_MAX / sizeof(*s->style_attributes)" below is both good and bad: It is good because the compiler can see for arches where size_t is 64bit and unsigned is 32bit that this is always true, so that it can be optimized away; it is bad, because compilers emit warnings for this. The warning from Clang could be shut up by first checking whether SIZE_MAX / sizeof(*s->style_attributes) exceeds UINT_MAX; but GCC still warns in this case. Unfortunately one can't use sizeof in preprocessor checks. Notice that av_fast_realloc() ensures that s->count * sizeof(*s->style_attributes) is <= UINT_MAX, so that s->count + 1 can't overflow. libavcodec/movtextenc.c | 124 ++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 74 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index dcdbf16e08..73d998d080 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -73,12 +73,13 @@ typedef struct { ASSSplitContext *ass_ctx; ASSStyle *ass_dialog_style; + StyleBox *style_attributes; + unsigned count; + unsigned style_attributes_bytes_allocated; + StyleBox style_attributes_temp; AVBPrint buffer; - StyleBox **style_attributes; - StyleBox *style_attributes_temp; HighlightBox hlit; HilightcolorBox hclr; - int count; uint8_t box_flags; StyleBox d; uint16_t text_pos; @@ -96,22 +97,12 @@ typedef struct { static void mov_text_cleanup(MovTextContext *s) { - int j; - if (s->box_flags & STYL_BOX) { - for (j = 0; j < s->count; j++) { - av_freep(&s->style_attributes[j]); - } - av_freep(&s->style_attributes); - s->count = 0; - } - if (s->style_attributes_temp) { - *s->style_attributes_temp = s->d; - } + s->count = 0; + s->style_attributes_temp = s->d; } static void encode_styl(MovTextContext *s, uint32_t tsmb_type) { - int j; uint32_t tsmb_size; uint16_t style_entries; if ((s->box_flags & STYL_BOX) && s->count) { @@ -124,20 +115,20 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) av_bprint_append_any(&s->buffer, &tsmb_size, 4); av_bprint_append_any(&s->buffer, &tsmb_type, 4); av_bprint_append_any(&s->buffer, &style_entries, 2); - for (j = 0; j < s->count; j++) { + for (unsigned j = 0; j < s->count; j++) { uint16_t style_start, style_end, style_fontID; uint32_t style_color; - style_start = AV_RB16(&s->style_attributes[j]->style_start); - style_end = AV_RB16(&s->style_attributes[j]->style_end); - style_color = AV_RB32(&s->style_attributes[j]->style_color); - style_fontID = AV_RB16(&s->style_attributes[j]->style_fontID); + style_start = AV_RB16(&s->style_attributes[j].style_start); + style_end = AV_RB16(&s->style_attributes[j].style_end); + style_color = AV_RB32(&s->style_attributes[j].style_color); + style_fontID = AV_RB16(&s->style_attributes[j].style_fontID); av_bprint_append_any(&s->buffer, &style_start, 2); av_bprint_append_any(&s->buffer, &style_end, 2); av_bprint_append_any(&s->buffer, &style_fontID, 2); - av_bprint_append_any(&s->buffer, &s->style_attributes[j]->style_flag, 1); - av_bprint_append_any(&s->buffer, &s->style_attributes[j]->style_fontsize, 1); + av_bprint_append_any(&s->buffer, &s->style_attributes[j].style_flag, 1); + av_bprint_append_any(&s->buffer, &s->style_attributes[j].style_fontsize, 1); av_bprint_append_any(&s->buffer, &style_color, 4); } } @@ -186,17 +177,10 @@ const static size_t box_count = FF_ARRAY_ELEMS(box_types); static int mov_text_encode_close(AVCodecContext *avctx) { MovTextContext *s = avctx->priv_data; - int i; ff_ass_split_free(s->ass_ctx); - if (s->style_attributes) { - for (i = 0; i < s->count; i++) { - av_freep(&s->style_attributes[i]); - } - av_freep(&s->style_attributes); - } + av_freep(&s->style_attributes); av_freep(&s->fonts); - av_freep(&s->style_attributes_temp); av_bprint_finalize(&s->buffer, NULL); return 0; } @@ -368,12 +352,6 @@ static av_cold int mov_text_encode_init(AVCodecContext *avctx) av_bprint_init(&s->buffer, 0, AV_BPRINT_SIZE_UNLIMITED); - s->style_attributes_temp = av_mallocz(sizeof(*s->style_attributes_temp)); - if (!s->style_attributes_temp) { - ret = AVERROR(ENOMEM); - goto fail; - } - s->ass_ctx = ff_ass_split(avctx->subtitle_header); if (!s->ass_ctx) { ret = AVERROR_INVALIDDATA; @@ -394,30 +372,34 @@ fail: static int mov_text_style_start(MovTextContext *s) { // there's an existing style entry - if (s->style_attributes_temp->style_start == s->text_pos) + if (s->style_attributes_temp.style_start == s->text_pos) // Still at same text pos, use same entry return 1; - if (s->style_attributes_temp->style_flag != s->d.style_flag || - s->style_attributes_temp->style_color != s->d.style_color || - s->style_attributes_temp->style_fontID != s->d.style_fontID || - s->style_attributes_temp->style_fontsize != s->d.style_fontsize) { + if (s->style_attributes_temp.style_flag != s->d.style_flag || + s->style_attributes_temp.style_color != s->d.style_color || + s->style_attributes_temp.style_fontID != s->d.style_fontID || + s->style_attributes_temp.style_fontsize != s->d.style_fontsize) { + StyleBox *tmp; + // last style != defaults, end the style entry and start a new one - s->box_flags |= STYL_BOX; - s->style_attributes_temp->style_end = s->text_pos; - av_dynarray_add(&s->style_attributes, &s->count, s->style_attributes_temp); - s->style_attributes_temp = av_malloc(sizeof(*s->style_attributes_temp)); - if (!s->style_attributes_temp) { + if (s->count + 1 > SIZE_MAX / sizeof(*s->style_attributes) || + !(tmp = av_fast_realloc(s->style_attributes, + &s->style_attributes_bytes_allocated, + (s->count + 1) * sizeof(*s->style_attributes)))) { mov_text_cleanup(s); av_bprint_clear(&s->buffer); s->box_flags &= ~STYL_BOX; return 0; } - - *s->style_attributes_temp = s->d; - s->style_attributes_temp->style_start = s->text_pos; + s->style_attributes = tmp; + s->style_attributes_temp.style_end = s->text_pos; + s->style_attributes[s->count++] = s->style_attributes_temp; + s->box_flags |= STYL_BOX; + s->style_attributes_temp = s->d; + s->style_attributes_temp.style_start = s->text_pos; } else { // style entry matches defaults, drop entry - *s->style_attributes_temp = s->d; - s->style_attributes_temp->style_start = s->text_pos; + s->style_attributes_temp = s->d; + s->style_attributes_temp.style_start = s->text_pos; } return 1; } @@ -442,13 +424,12 @@ static uint8_t mov_text_style_to_flag(const char style) static void mov_text_style_set(MovTextContext *s, uint8_t style_flags) { - if (!s->style_attributes_temp || - !((s->style_attributes_temp->style_flag & style_flags) ^ style_flags)) { + if (!((s->style_attributes_temp.style_flag & style_flags) ^ style_flags)) { // setting flags that that are already set return; } if (mov_text_style_start(s)) - s->style_attributes_temp->style_flag |= style_flags; + s->style_attributes_temp.style_flag |= style_flags; } static void mov_text_style_cb(void *priv, const char style, int close) @@ -456,29 +437,27 @@ static void mov_text_style_cb(void *priv, const char style, int close) MovTextContext *s = priv; uint8_t style_flag = mov_text_style_to_flag(style); - if (!s->style_attributes_temp || - !!(s->style_attributes_temp->style_flag & style_flag) != close) { + if (!!(s->style_attributes_temp.style_flag & style_flag) != close) { // setting flag that is already set return; } if (mov_text_style_start(s)) { if (!close) - s->style_attributes_temp->style_flag |= style_flag; + s->style_attributes_temp.style_flag |= style_flag; else - s->style_attributes_temp->style_flag &= ~style_flag; + s->style_attributes_temp.style_flag &= ~style_flag; } } static void mov_text_color_set(MovTextContext *s, uint32_t color) { - if (!s->style_attributes_temp || - (s->style_attributes_temp->style_color & 0xffffff00) == color) { + if ((s->style_attributes_temp.style_color & 0xffffff00) == color) { // color hasn't changed return; } if (mov_text_style_start(s)) - s->style_attributes_temp->style_color = (color & 0xffffff00) | - (s->style_attributes_temp->style_color & 0xff); + s->style_attributes_temp.style_color = (color & 0xffffff00) | + (s->style_attributes_temp.style_color & 0xff); } static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color_id) @@ -491,7 +470,7 @@ static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color } else if (color_id == 2) { //secondary color changes if (!(s->box_flags & HCLR_BOX)) // Highlight alpha not set yet, use current primary alpha - s->hclr.color = s->style_attributes_temp->style_color; + s->hclr.color = s->style_attributes_temp.style_color; if (!(s->box_flags & HLIT_BOX) || s->hlit.start == s->text_pos) { s->box_flags |= HCLR_BOX; s->box_flags |= HLIT_BOX; @@ -510,14 +489,13 @@ static void mov_text_color_cb(void *priv, unsigned int color, unsigned int color static void mov_text_alpha_set(MovTextContext *s, uint8_t alpha) { - if (!s->style_attributes_temp || - (s->style_attributes_temp->style_color & 0xff) == alpha) { + if ((s->style_attributes_temp.style_color & 0xff) == alpha) { // color hasn't changed return; } if (mov_text_style_start(s)) - s->style_attributes_temp->style_color = - (s->style_attributes_temp->style_color & 0xffffff00) | alpha; + s->style_attributes_temp.style_color = + (s->style_attributes_temp.style_color & 0xffffff00) | alpha; } static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id) @@ -530,7 +508,7 @@ static void mov_text_alpha_cb(void *priv, int alpha, int alpha_id) else if (alpha_id == 2) { //secondary alpha changes if (!(s->box_flags & HCLR_BOX)) // Highlight color not set yet, use current primary color - s->hclr.color = s->style_attributes_temp->style_color; + s->hclr.color = s->style_attributes_temp.style_color; if (!(s->box_flags & HLIT_BOX) || s->hlit.start == s->text_pos) { s->box_flags |= HCLR_BOX; s->box_flags |= HLIT_BOX; @@ -556,13 +534,12 @@ static uint16_t find_font_id(MovTextContext *s, const char *name) static void mov_text_font_name_set(MovTextContext *s, const char *name) { int fontID = find_font_id(s, name); - if (!s->style_attributes_temp || - s->style_attributes_temp->style_fontID == fontID) { + if (s->style_attributes_temp.style_fontID == fontID) { // color hasn't changed return; } if (mov_text_style_start(s)) - s->style_attributes_temp->style_fontID = fontID; + s->style_attributes_temp.style_fontID = fontID; } static void mov_text_font_name_cb(void *priv, const char *name) @@ -573,13 +550,12 @@ static void mov_text_font_name_cb(void *priv, const char *name) static void mov_text_font_size_set(MovTextContext *s, int size) { size = FONTSIZE_SCALE(s, size); - if (!s->style_attributes_temp || - s->style_attributes_temp->style_fontsize == size) { + if (s->style_attributes_temp.style_fontsize == size) { // color hasn't changed return; } if (mov_text_style_start(s)) - s->style_attributes_temp->style_fontsize = size; + s->style_attributes_temp.style_fontsize = size; } static void mov_text_font_size_cb(void *priv, int size) From patchwork Sat Oct 17 07:37:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23033 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 8F14744A23D for ; Sat, 17 Oct 2020 10:38:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6CD7168BA02; Sat, 17 Oct 2020 10:38:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B22E368B927 for ; Sat, 17 Oct 2020 10:38:25 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id h5so5909124wrv.7 for ; Sat, 17 Oct 2020 00:38:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CBFPw5cVHz4GEbjIHzvWOntmga/2k6nQD4VwkQUhfu0=; b=eMlRr+f0vBi/z7znd/aWVxIWvWHS8uwrN5JyCt+evHqdgqn8W0HIlcBR9+vv0sUTbo P10KR+3FyJgXRwgWAgRDrKAeIT7Ir29GsLeCj+mOlIRYsywZcBZYz6RkFTyxdpP+scts AwR3QPJ5+B+YjpZvPVUhFYydXlR6ZbkFvb+swbYlUnfqxBqHiiXiQs9H2t50Aumlw//8 k8UDRvOs4tV0aZ5ywOD59Pvsx7ti6QB+veHsy4NaRH60FzUWq+Df/zVEXiqwY70IGEn4 Xt38pKaGwSUBPK/ZQLEbodIXbV/odGDt9qxoNdc5cRVIavkDo06fMUix4VdKX4lbxPE6 xw2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CBFPw5cVHz4GEbjIHzvWOntmga/2k6nQD4VwkQUhfu0=; b=b9xl5k8HUT6XejD8wZQkuLXFVSQ8GexpK7ZFmggLTuwNcpfgSlERacUxAZwJqUJ6Sq TmJX4a83SO/pcYuq4b19eXYo5pbCio3d3DKmgK3SYU0bJjgijBH6hUf0SHykNU5hDWa3 uSOdrw1Bje/X1pfvGRjrUneKvFCDl4zTx/XHzEFLsErsh07QsOKzgEHBFbgPWxbcXWIG LxywNWfUtsgk7Sha3nrjDatGyP5egR8D3itKR1lTwag4VmDcyEJWxAIo3hMvXKIrfD+F WTYCmhGuLt8feC1KUkMr89b6vZZpBAqnzJZcq6Zd7sOpmF1iUyWQNg5PTGbDQaveAfIR UKoA== X-Gm-Message-State: AOAM533DCKSMR5rSmP32Q6HTEcdiEHdD05n4WjWmNAsATkZJDBV/5iGO UzVpWZo7l+WPGwLE+aKcbo3aQ1ARESs= X-Google-Smtp-Source: ABdhPJyAuYQOCEjZaVELbvmpqbl/Z8aJGB99RBlHvnQtIAM4Xdem9MzPGSOfYdaBnz7qcxA7DmNBSw== X-Received: by 2002:a5d:67c4:: with SMTP id n4mr760514wrw.125.1602920304792; Sat, 17 Oct 2020 00:38:24 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id 24sm5946553wmg.8.2020.10.17.00.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 00:38:24 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Oct 2020 09:37:42 +0200 Message-Id: <20201017073745.403153-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> References: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 5/8] avcodec/movtextenc: Fix undefined left shifts outside the range of int 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- Alternatively one could also change the types of the colors in ASSStyle (ass_split.h) to uint32_t. libavcodec/movtextenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 73d998d080..42fdf98042 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -45,7 +45,7 @@ #define DEFAULT_STYLE_COLOR 0xffffffff #define DEFAULT_STYLE_FLAG 0x00 -#define BGR_TO_RGB(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((c) >> 16) & 0xff)) +#define BGR_TO_RGB(c) (((c) & 0xff) << 16 | ((c) & 0xff00) | (((uint32_t)(c) >> 16) & 0xff)) #define FONTSIZE_SCALE(s,fs) ((fs) * (s)->font_scale_factor + 0.5) #define av_bprint_append_any(buf, data, size) av_bprint_append_data(buf, ((const char*)data), size) From patchwork Sat Oct 17 07:37:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23034 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 9D00844A23D for ; Sat, 17 Oct 2020 10:38:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5658F68B9C0; Sat, 17 Oct 2020 10:38:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0B13368B9A4 for ; Sat, 17 Oct 2020 10:38:27 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id i1so5933773wro.1 for ; Sat, 17 Oct 2020 00:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PfCVay6Ro2aP4E6LjT78ZkBpPbto2k9C2zVRl0L3Vp0=; b=O5HprF2d0WKmQk0GTIbxVqvqV/Pogq97XG9U+fuV+h/OoZ2ZARMnxUyxRu17VYWF65 0Oq8tGgi2qCnfjszLrMlm9qFVglvIIov2QmYIXKXYWPE7ihcyhfNhuUGpj8dZQlYDJgu WUXnbOsK4euL4gGL+1Zbvgz8GXdxKHmxw5Ogr0AuNpbbEYq+MTrq7wR2deil5eOLp7QD 1O7ToU2Mwf4VsWhjF81y26p5uqZVmXev8PsOGIRzABzeVKC0E/UkBzNfwco0GgdQSpoe A1idSHtpvTcm7ZIuRkhBWNRembK4+aC8dSO0H6pU/fBJqZfknlMSjIIkPyUFGmpybIo1 TTPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PfCVay6Ro2aP4E6LjT78ZkBpPbto2k9C2zVRl0L3Vp0=; b=aogGEaGfiWY4UnB0Tnc1uIyGU3bwNZhVRg76h5evHZ4VO2nrsjsfJRta3MCoZuRcS4 mPNIKKKcz+70yqOwgj/KS35H83m4FtcYukMoTnN2fldJZWEXq0LloraImMoik6qbH9x2 Yv5FzEQBC696X3DS47slBx1eSW6ChJowkJ6HckLWg2/qZQSWE0OzpSwdi0IaGpPr1aPG avzjvOPkJfsmbrQ5zSpImhNjdTFkCg4mccIBqTEa8/+leMcaPklRvYYpoil2VxeAZUJV 3naxG/HXC2RIPqhESuxUpkONGYMg3kbLug+VocGBc8KFtU9Pkp1h+d8Byvh/8lVl18MK Pu2A== X-Gm-Message-State: AOAM530bUDE3nD3tE/4NZI4ERNxXFJ1ZRPBokKl7ckkrk+4/usfYC2qz wiDmbThVWpFPNMzfXR6Y9O/9CQs+vQA= X-Google-Smtp-Source: ABdhPJxTqnTjqM7W9XNjfTGK2s3S3lIeygFxqhXl+V0nhy8XfIIfsu88LBJrnPZabl8L0NEWPmia0g== X-Received: by 2002:adf:e5cb:: with SMTP id a11mr8626299wrn.353.1602920306087; Sat, 17 Oct 2020 00:38:26 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id 24sm5946553wmg.8.2020.10.17.00.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 00:38:25 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Oct 2020 09:37:43 +0200 Message-Id: <20201017073745.403153-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> References: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 6/8] avcodec/movtextenc: Simplify writing to AVBPrint 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The mov_text encoder uses an AVBPrint to assemble the subtitles; yet mov_text subtitles are not pure text; they also have a binary portion that was mostly handled as follows: uint32_t size = /* calculation */; size = AV_RB32(&size); av_bprint_append_data(bprint, (const char*)&size, 4); Here AV_RB32() is a no-op on big-endian systems and a LE-BE swap on little-endian systems, making the output endian-independent. Yet this is ugly and unclean: On LE systems, the variable size from the snippet above won't contain the correct value any more. Furthermore, using this pattern leads to lots of small writes to the AVBPrint. This commit therefore changes this to using a temporary buffer instead: uint8_t buf[4]; AV_WB32(buf, /* size calculation */); av_bprint_append_data(bprint, buf, 4); This method also allows to use bigger buffers holding more than one element, saving calls to av_bprint_append_data() and reducing codesize. Signed-off-by: Andreas Rheinhardt --- No real change, just the typical rebase stuff. libavcodec/movtextenc.c | 153 +++++++++++++++++----------------------- 1 file changed, 66 insertions(+), 87 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 42fdf98042..908b2bfde5 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -29,6 +29,7 @@ #include "libavutil/common.h" #include "ass_split.h" #include "ass.h" +#include "bytestream.h" #define STYLE_FLAG_BOLD (1<<0) #define STYLE_FLAG_ITALIC (1<<1) @@ -103,33 +104,27 @@ static void mov_text_cleanup(MovTextContext *s) static void encode_styl(MovTextContext *s, uint32_t tsmb_type) { - uint32_t tsmb_size; - uint16_t style_entries; if ((s->box_flags & STYL_BOX) && s->count) { - tsmb_size = s->count * STYLE_RECORD_SIZE + SIZE_ADD; - tsmb_size = AV_RB32(&tsmb_size); - tsmb_type = AV_RB32(&tsmb_type); - style_entries = AV_RB16(&s->count); + uint8_t buf[12], *p = buf; + + bytestream_put_be32(&p, s->count * STYLE_RECORD_SIZE + SIZE_ADD); + bytestream_put_be32(&p, tsmb_type); + bytestream_put_be16(&p, s->count); /*The above three attributes are hard coded for now but will come from ASS style in the future*/ - av_bprint_append_any(&s->buffer, &tsmb_size, 4); - av_bprint_append_any(&s->buffer, &tsmb_type, 4); - av_bprint_append_any(&s->buffer, &style_entries, 2); + av_bprint_append_any(&s->buffer, buf, 10); for (unsigned j = 0; j < s->count; j++) { - uint16_t style_start, style_end, style_fontID; - uint32_t style_color; - - style_start = AV_RB16(&s->style_attributes[j].style_start); - style_end = AV_RB16(&s->style_attributes[j].style_end); - style_color = AV_RB32(&s->style_attributes[j].style_color); - style_fontID = AV_RB16(&s->style_attributes[j].style_fontID); - - av_bprint_append_any(&s->buffer, &style_start, 2); - av_bprint_append_any(&s->buffer, &style_end, 2); - av_bprint_append_any(&s->buffer, &style_fontID, 2); - av_bprint_append_any(&s->buffer, &s->style_attributes[j].style_flag, 1); - av_bprint_append_any(&s->buffer, &s->style_attributes[j].style_fontsize, 1); - av_bprint_append_any(&s->buffer, &style_color, 4); + const StyleBox *style = &s->style_attributes[j]; + + p = buf; + bytestream_put_be16(&p, style->style_start); + bytestream_put_be16(&p, style->style_end); + bytestream_put_be16(&p, style->style_fontID); + bytestream_put_byte(&p, style->style_flag); + bytestream_put_byte(&p, style->style_fontsize); + bytestream_put_be32(&p, style->style_color); + + av_bprint_append_any(&s->buffer, buf, 12); } } mov_text_cleanup(s); @@ -137,32 +132,28 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) static void encode_hlit(MovTextContext *s, uint32_t tsmb_type) { - uint32_t tsmb_size; - uint16_t start, end; if (s->box_flags & HLIT_BOX) { - tsmb_size = 12; - tsmb_size = AV_RB32(&tsmb_size); - tsmb_type = AV_RB32(&tsmb_type); - start = AV_RB16(&s->hlit.start); - end = AV_RB16(&s->hlit.end); - av_bprint_append_any(&s->buffer, &tsmb_size, 4); - av_bprint_append_any(&s->buffer, &tsmb_type, 4); - av_bprint_append_any(&s->buffer, &start, 2); - av_bprint_append_any(&s->buffer, &end, 2); + uint8_t buf[12], *p = buf; + + bytestream_put_be32(&p, 12); + bytestream_put_be32(&p, tsmb_type); + bytestream_put_be16(&p, s->hlit.start); + bytestream_put_be16(&p, s->hlit.end); + + av_bprint_append_any(&s->buffer, buf, 12); } } static void encode_hclr(MovTextContext *s, uint32_t tsmb_type) { - uint32_t tsmb_size, color; if (s->box_flags & HCLR_BOX) { - tsmb_size = 12; - tsmb_size = AV_RB32(&tsmb_size); - tsmb_type = AV_RB32(&tsmb_type); - color = AV_RB32(&s->hclr.color); - av_bprint_append_any(&s->buffer, &tsmb_size, 4); - av_bprint_append_any(&s->buffer, &tsmb_type, 4); - av_bprint_append_any(&s->buffer, &color, 4); + uint8_t buf[12], *p = buf; + + bytestream_put_be32(&p, 12); + bytestream_put_be32(&p, tsmb_type); + bytestream_put_be32(&p, s->hclr.color); + + av_bprint_append_any(&s->buffer, buf, 12); } } @@ -190,25 +181,21 @@ static int encode_sample_description(AVCodecContext *avctx) ASS *ass; ASSStyle *style; int i, j; - uint32_t tsmb_size, tsmb_type, back_color = 0, style_color; - uint16_t style_start, style_end, fontID, count; + uint32_t back_color = 0; int font_names_total_len = 0; MovTextContext *s = avctx->priv_data; + uint8_t buf[30], *p = buf; - static const uint8_t display_and_justification[] = { - 0x00, 0x00, 0x00, 0x00, // uint32_t displayFlags - 0x01, // int8_t horizontal-justification - 0xFF, // int8_t vertical-justification - }; + // 0x00, 0x00, 0x00, 0x00, // uint32_t displayFlags + // 0x01, // int8_t horizontal-justification + // 0xFF, // int8_t vertical-justification // 0x00, 0x00, 0x00, 0x00, // uint8_t background-color-rgba[4] - static const uint8_t box_record[] = { // BoxRecord { - 0x00, 0x00, // int16_t top - 0x00, 0x00, // int16_t left - 0x00, 0x00, // int16_t bottom - 0x00, 0x00, // int16_t right + // 0x00, 0x00, // int16_t top + // 0x00, 0x00, // int16_t left + // 0x00, 0x00, // int16_t bottom + // 0x00, 0x00, // int16_t right // }; - }; // StyleRecord { // 0x00, 0x00, // uint16_t startChar // 0x00, 0x00, // uint16_t endChar @@ -256,25 +243,19 @@ static int encode_sample_description(AVCodecContext *avctx) (255 - ((uint32_t)style->back_color >> 24)); } - av_bprint_append_any(&s->buffer, display_and_justification, - sizeof(display_and_justification)); - back_color = AV_RB32(&back_color); - av_bprint_append_any(&s->buffer, &back_color, 4); - // BoxRecord { - av_bprint_append_any(&s->buffer, box_record, sizeof(box_record)); - // }; + bytestream_put_be32(&p, 0); // displayFlags + bytestream_put_be16(&p, 0x01FF); // horizontal/vertical justification (2x int8_t) + bytestream_put_be32(&p, back_color); + bytestream_put_be64(&p, 0); // BoxRecord - 4xint16_t: top, left, bottom, right // StyleRecord { - style_start = AV_RB16(&s->d.style_start); - style_end = AV_RB16(&s->d.style_end); - fontID = AV_RB16(&s->d.style_fontID); - style_color = AV_RB32(&s->d.style_color); - av_bprint_append_any(&s->buffer, &style_start, 2); - av_bprint_append_any(&s->buffer, &style_end, 2); - av_bprint_append_any(&s->buffer, &fontID, 2); - av_bprint_append_any(&s->buffer, &s->d.style_flag, 1); - av_bprint_append_any(&s->buffer, &s->d.style_fontsize, 1); - av_bprint_append_any(&s->buffer, &style_color, 4); + bytestream_put_be16(&p, s->d.style_start); + bytestream_put_be16(&p, s->d.style_end); + bytestream_put_be16(&p, s->d.style_fontID); + bytestream_put_byte(&p, s->d.style_flag); + bytestream_put_byte(&p, s->d.style_fontsize); + bytestream_put_be32(&p, s->d.style_color); // }; + av_bprint_append_any(&s->buffer, buf, 30); // Build font table // We can't build a complete font table since that would require @@ -306,23 +287,21 @@ static int encode_sample_description(AVCodecContext *avctx) av_dynarray_add(&s->fonts, &s->font_count, (char*)"Serif"); // FontTableBox { - tsmb_size = SIZE_ADD + 3 * s->font_count + font_names_total_len; - tsmb_size = AV_RB32(&tsmb_size); - tsmb_type = MKBETAG('f','t','a','b'); - tsmb_type = AV_RB32(&tsmb_type); - count = s->font_count; - count = AV_RB16(&count); - av_bprint_append_any(&s->buffer, &tsmb_size, 4); - av_bprint_append_any(&s->buffer, &tsmb_type, 4); - av_bprint_append_any(&s->buffer, &count, 2); + p = buf; + bytestream_put_be32(&p, SIZE_ADD + 3 * s->font_count + font_names_total_len); // Size + bytestream_put_be32(&p, MKBETAG('f','t','a','b')); + bytestream_put_be16(&p, s->font_count); + + av_bprint_append_any(&s->buffer, buf, 10); // FontRecord { for (i = 0; i < s->font_count; i++) { - uint8_t len; - fontID = i + 1; - fontID = AV_RB16(&fontID); - av_bprint_append_any(&s->buffer, &fontID, 2); - len = strlen(s->fonts[i]); - av_bprint_append_any(&s->buffer, &len, 1); + size_t len = strlen(s->fonts[i]); + + p = buf; + bytestream_put_be16(&p, i + 1); //fontID + bytestream_put_byte(&p, len); + + av_bprint_append_any(&s->buffer, buf, 3); av_bprint_append_any(&s->buffer, s->fonts[i], len); } // }; From patchwork Sat Oct 17 07:37:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23035 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 D65B644A23D for ; Sat, 17 Oct 2020 10:38:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BCC0268BA7C; Sat, 17 Oct 2020 10:38:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EA4B768B9A4 for ; Sat, 17 Oct 2020 10:38:27 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id b8so5962073wrn.0 for ; Sat, 17 Oct 2020 00:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rI/YVRAHs3AopwFRHGbnnSlAJGd2gtkO+BYHCVvebks=; b=HMKvpqAdXGsIc5nAHTAyHFa1jhzIQ1M3sgviiD2g5NQj1Hp50PfY2h+NcPm522n2Yn VCKzP/P1ayn4nH5rWCJMPc5G4My4vOkRUvz3egU5KOiM733WeuUD67bT/bqgwcJQ56o8 3Ka+YVx4jl2qJheVJROreNOVSNkoeImXh7LTRMO6N9wXNo9iVy+owtVROK9AHBbATSHp G4w9tcGuZRzlCAttV8TSf70c1CKPF73mcsJo+nzHsIOstz1Qnq7ws9vAjusN3p25Bgnk fNOx949mV+GwO/n5WHkGTcc+M3ZdqdpdnMgz5YRG4lySfBThiV+JxzCxlwT5frFT7yiI AJqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rI/YVRAHs3AopwFRHGbnnSlAJGd2gtkO+BYHCVvebks=; b=dwWtfvCVuXD070wSgalPfP7y2MAwxhPIdMwi4UXTxYwAWBfQHqGhP4icZ8TjMj+bs2 FaeGXJ1je1fu1IxZ6AqpIIWZiN77wQmFKFNq9iqY7FvjjvNosCLR5eY0gzNitkP66kDb 6L10mluRuiyvVCsEFdleAd+2t48nxdoto9e7EZwoAdDz5gKgowiYdMwXWqVo/79dTPai Fvt6Gf4Cr4ncPz3OFhqx5Q6vsX+H/tZgx+ZagCPhrdUJAcP9R99jLwzthPxt95sLUdLF 7dozfEulCNJ7Dj9xyel4oyPoS4YtTczV7EQHMfYRfUcAOMWdK4uZAwJ64LBgRQowjykt ZqhA== X-Gm-Message-State: AOAM533MBbueX3CDMSzySmjZ3sYsZoZRq+QIepW9SS0m+GJ/lr2bIPch zkFs21cH9f4IX6PkrIM52wK9KN3h6mY= X-Google-Smtp-Source: ABdhPJxBapeCmZhcU0Y/x4RUw1zJtJ1/eugE+eYhaE837MT0/rrSPA9KOWGbCVUsfT8/sKfpaOIdOw== X-Received: by 2002:adf:f2c9:: with SMTP id d9mr8575253wrp.319.1602920307126; Sat, 17 Oct 2020 00:38:27 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id 24sm5946553wmg.8.2020.10.17.00.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 00:38:26 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Oct 2020 09:37:44 +0200 Message-Id: <20201017073745.403153-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> References: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 7/8] avcodec/movtextenc: Remove redundant function parameters 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" It makes no sense to call the functions to write styl, hlit or hclr boxes with a different box name than "styl", "hlit" or "hclr". Therefore this commit inlines these values in the functions, removes the function parameter containing the box's name and removes the (non obsolete) box names from the list of boxes. Signed-off-by: Andreas Rheinhardt --- libavcodec/movtextenc.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 908b2bfde5..2082dc9b25 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -92,8 +92,7 @@ typedef struct { } MovTextContext; typedef struct { - uint32_t type; - void (*encode)(MovTextContext *s, uint32_t tsmb_type); + void (*encode)(MovTextContext *s); } Box; static void mov_text_cleanup(MovTextContext *s) @@ -102,13 +101,13 @@ static void mov_text_cleanup(MovTextContext *s) s->style_attributes_temp = s->d; } -static void encode_styl(MovTextContext *s, uint32_t tsmb_type) +static void encode_styl(MovTextContext *s) { if ((s->box_flags & STYL_BOX) && s->count) { uint8_t buf[12], *p = buf; bytestream_put_be32(&p, s->count * STYLE_RECORD_SIZE + SIZE_ADD); - bytestream_put_be32(&p, tsmb_type); + bytestream_put_be32(&p, MKBETAG('s','t','y','l')); bytestream_put_be16(&p, s->count); /*The above three attributes are hard coded for now but will come from ASS style in the future*/ @@ -130,13 +129,13 @@ static void encode_styl(MovTextContext *s, uint32_t tsmb_type) mov_text_cleanup(s); } -static void encode_hlit(MovTextContext *s, uint32_t tsmb_type) +static void encode_hlit(MovTextContext *s) { if (s->box_flags & HLIT_BOX) { uint8_t buf[12], *p = buf; bytestream_put_be32(&p, 12); - bytestream_put_be32(&p, tsmb_type); + bytestream_put_be32(&p, MKBETAG('h','l','i','t')); bytestream_put_be16(&p, s->hlit.start); bytestream_put_be16(&p, s->hlit.end); @@ -144,13 +143,13 @@ static void encode_hlit(MovTextContext *s, uint32_t tsmb_type) } } -static void encode_hclr(MovTextContext *s, uint32_t tsmb_type) +static void encode_hclr(MovTextContext *s) { if (s->box_flags & HCLR_BOX) { uint8_t buf[12], *p = buf; bytestream_put_be32(&p, 12); - bytestream_put_be32(&p, tsmb_type); + bytestream_put_be32(&p, MKBETAG('h','c','l','r')); bytestream_put_be32(&p, s->hclr.color); av_bprint_append_any(&s->buffer, buf, 12); @@ -158,9 +157,9 @@ static void encode_hclr(MovTextContext *s, uint32_t tsmb_type) } static const Box box_types[] = { - { MKBETAG('s','t','y','l'), encode_styl }, - { MKBETAG('h','l','i','t'), encode_hlit }, - { MKBETAG('h','c','l','r'), encode_hclr }, + { encode_styl }, + { encode_hlit }, + { encode_hclr }, }; const static size_t box_count = FF_ARRAY_ELEMS(box_types); @@ -682,7 +681,7 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf, #endif for (j = 0; j < box_count; j++) { - box_types[j].encode(s, box_types[j].type); + box_types[j].encode(s); } } From patchwork Sat Oct 17 07:37:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23036 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 9DA6744A23D for ; Sat, 17 Oct 2020 10:38:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B5D868BABE; Sat, 17 Oct 2020 10:38:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1366568B94D for ; Sat, 17 Oct 2020 10:38:29 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id j7so1819141wrt.9 for ; Sat, 17 Oct 2020 00:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S215sPQwqZlVljejHzGFvveP557FfjfyAr7sDVPAElI=; b=eS5bAYAmGiAli6Hk1cYSXhBRMV69QeSHySYfclbaCKwxWvAvNSymmN/WzHqNRNQDo+ G4r4hDAALYkhA8N7pCygvNRGPSDN5KQXID9eskPGcuWWQSIEr+KxGnBBTk88LZPhAnnd sOMQQrrRN5wM95caeI3rc758KiJ5LNZUTvqvBaeDa+ymRsn+G8UTj+m8uCv5RwdrryD5 V9Kqs1LMUj7GfqDaTY47J537X/LfXEPdO3DAkVhROFJgOPrwgm5YD6fWbMaINJJNi0ak oL0OkbJHBFnu80FKB2D9q4RJWBP2pf1hIRHFeSp5ElZqpYAiYOG19hU38AKnKB0Q+VqH GYrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S215sPQwqZlVljejHzGFvveP557FfjfyAr7sDVPAElI=; b=J2+NAv4h2BUl55f1YX1uxIj02kes6xq66Vbu2MTd2BRetbx0SPNcYbS4j0SLXVNZB/ Nlwou596Ah3iY5rbu+qgFaz/s2D1w9vntH6aMtnT2FF09fJuOmgIMea8BPpjNAQ8nel9 fqoe96IvRaESV9qHbdi4dolW8qrff12JQqYADY1pq/IJF5FmtC3PrqlNnCOP/TmI5FDL 9zb5uVrZUOKeSVZrFGQ3GAz70DhcE6xZRz0yF5kRlgdZcKAwY56JNFI8NphWHJ5BBmPW rs6ipCyfmFusYJHorH6z+RKhn/iS01EnH2TdFyhdyXqeMwcrpT9mv7earYnTWEg4Duyw MmmQ== X-Gm-Message-State: AOAM5338Af4vPPpVgX9VDoj7qcXbaI+mQ3q9DUT0IYaY4+gLhMW33Y04 i61IGBHE2FxuLQITgqvbVSNT7dBKMEc= X-Google-Smtp-Source: ABdhPJwpStHIJ1t+8qHRAkEonGCgh0/r5/aTcznzbAyN+RbOvFheLhUhZbV6bfbKyOMgl9EbvxA5sA== X-Received: by 2002:adf:a1cb:: with SMTP id v11mr8380663wrv.86.1602920308343; Sat, 17 Oct 2020 00:38:28 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id 24sm5946553wmg.8.2020.10.17.00.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Oct 2020 00:38:27 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Oct 2020 09:37:45 +0200 Message-Id: <20201017073745.403153-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> References: <20201017073745.403153-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 8/8] avcodec/movtextenc: Cleanup generically on init failure 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/movtextenc.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 2082dc9b25..1bef21e0b9 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -30,6 +30,7 @@ #include "ass_split.h" #include "ass.h" #include "bytestream.h" +#include "internal.h" #define STYLE_FLAG_BOLD (1<<0) #define STYLE_FLAG_ITALIC (1<<1) @@ -331,19 +332,13 @@ static av_cold int mov_text_encode_init(AVCodecContext *avctx) av_bprint_init(&s->buffer, 0, AV_BPRINT_SIZE_UNLIMITED); s->ass_ctx = ff_ass_split(avctx->subtitle_header); - if (!s->ass_ctx) { - ret = AVERROR_INVALIDDATA; - goto fail; - } + if (!s->ass_ctx) + return AVERROR_INVALIDDATA; ret = encode_sample_description(avctx); if (ret < 0) - goto fail; + return ret; return 0; - -fail: - mov_text_encode_close(avctx); - return ret; } // Start a new style box if needed @@ -736,4 +731,5 @@ AVCodec ff_movtext_encoder = { .init = mov_text_encode_init, .encode_sub = mov_text_encode_frame, .close = mov_text_encode_close, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, };