From patchwork Tue Jun 15 23:32:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 28346 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:c91a:0:0:0:0:0 with SMTP id z26csp4312456iol; Tue, 15 Jun 2021 16:36:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNhiWQhxYhV2yok1vYHcGPz617k0rx2LTBp4jbfAYVdlc9YTMxRsjomg3msI3OglO6WgD+ X-Received: by 2002:a17:907:2642:: with SMTP id ar2mr371641ejc.391.1623800207220; Tue, 15 Jun 2021 16:36:47 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 5si391853ejh.535.2021.06.15.16.36.46; Tue, 15 Jun 2021 16:36:47 -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; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=s5gcyeQy; 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 DA7DA689B62; Wed, 16 Jun 2021 02:33:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2104.outbound.protection.outlook.com [40.92.91.104]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8FC36689B33 for ; Wed, 16 Jun 2021 02:33:46 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=myl7XlaJi/IBNoHDScsd3C42ZjORDJjbO/wDgJifdiEUzYntWoRfPEJ5UovfZQvV40UgFhb/Ry0DZRFbvKCC6xkFWoB3tTmd8+ii5nj7oAHMBrFvJkYmPZfDFCvF4dxWpHl62I4BTwdA7mxs2fNITs5KeCs3JV1itlEnuULLKSg85BcmlAUBd+plMfY4bOnD+GNyTxdsOTS9j6DxXJM2SpR0kBk48gmopRtEZECsFQNEnYxmxZRSBt2zeOkPtVvsEutb7NAHvPijWk8IKw51bcZFy/UHmDwIQjytAy/g8m5ywg/CoqqLDUv6s8MddPU6OgpUc1A7misU2u8PpxeZgg== 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-SenderADCheck; bh=OQfGdEj6kNwffsXS0lq0b2DHC0sb38HRCtJVP+0c/Zo=; b=lJVutVDuT91W2qak/+rgzTFbAmmlFNa5dMdXeqG686zGo70yWi1r9dmuw2QtAedWQMpda6BC2RvJ7H2uvU+IBRT/hWVqmsX82KAz7IpmKHVRMe7/iawQi/b4U+LIobRJhgxd9LaD4t7X7plRx/UirXqZkrvfiUkSPRhZJ1wB41IsnP3p4B+jm7VfWuz2o+YUdruZeJ431Kg+NsyIonDDR/qlpN9hRXqsON2uGGi0mEhIsxFl6JkIbf2rj/Am69p8N1he5jKYCWCZvc19dtOIhwklcbWcXH7i7bufB3VuCRhC5HXgO3PI7wv4+4DRlzSYXzBPpAwWgdcoNq7LrxYZ+g== 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=OQfGdEj6kNwffsXS0lq0b2DHC0sb38HRCtJVP+0c/Zo=; b=s5gcyeQy8p1f+OM4XuSrlpnI5L0cf2beq5eAYfrl0C0hsDvTh6UuYFr1mPHoolARo6xTyl8czcaupDzexhlTTg2T0KSrdQ7xUPMKIGyjxFzfVtocD7B4pmI4mG+vH7bby/GklmtstwAdX8UKgcy/Nyd5kZvX7usz94kcRiwHA0qzqhoUIgymo3guHR6vGX8b+/XkRFEmSmDfh5AGHhMsFlSq3qXwdvvL4bcnL1SG7NagUQ1YyUJcwJuylBrBpz1neyuGaTE5BTcW5yj6Qu3AjaRE6k8rQiMbJPIXR5jMqpnuKlaoFwENJZyy8ZP6/jUHCp79+KXblJT/+eXha6dOXw== Received: from DB8EUR05FT030.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc0f::52) by DB8EUR05HT119.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc0f::465) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21; Tue, 15 Jun 2021 23:33:45 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:fc0f::40) by DB8EUR05FT030.mail.protection.outlook.com (2a01:111:e400:fc0f::228) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16 via Frontend Transport; Tue, 15 Jun 2021 23:33:44 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:8C5DBAB2AEDC97B7FF5710B1EAFAAE37434F9C003BD511203DEBD47C8714719E; UpperCasedChecksum:D772F0482F1DEF833DC3F8D7CC6A9EDB1AA0ABD4F2646FABEECD9DEFCB41DB06; SizeAsReceived:7581; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::f4cc:63fc:9cef:37fb]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::f4cc:63fc:9cef:37fb%6]) with mapi id 15.20.4219.025; Tue, 15 Jun 2021 23:33:44 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 16 Jun 2021 01:32:14 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [cDGpAVagzJIv0SnAK8i7F4c7X6bNZYm9] X-ClientProxiedBy: PR3P189CA0063.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::8) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210615233243.1173928-24-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.97.82) by PR3P189CA0063.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.20 via Frontend Transport; Tue, 15 Jun 2021 23:33:44 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: f24dbaa1-c112-49e1-f87c-08d93056043e X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiR9SlwCHtPrt+MV8TUUwp4pWhkGqqrkWQJ/G2nBDhW1ViMQFHGvL0m+wmtApeSvE/Spy4GWSmsQRH5CWTHd/m1gGLfFEYj/0TS5PNIsXjrah5i+TMPwQx18QSWWGRzdLDx1ZhCvt3KTu2H8btvlGv1TukI0E/Y+0j9L/itU95Ae2t/DvqxEl1HthTCR09qPzbvM2O38pTsMDYD0QuY6JeRqT7U5Ad81/9qtZeEPxXMIu5xt4WCbluKhi0dXwgrwFz1K9MvJAuSkPuZCehrHPX/wSjBmojFdphEcORQ8zVTynJeBshlP5Llr7in20/6+px3TUfjdNU5+CtUOoCUzlN2nuQXy5iRMVEKnRxz9wPuhtFXTkSCFXYiEyhHa7iq+xq3GuiURXNuB/orUDGdUjOzUdVJViB8bSyOJd6fc3pIowizrQ0e9T6wWW+HWiq4uolXQDs5jSg0+UAcXzsh7ckOnd4OBM1cwfwxYse84wLdZ4Ko1Vf7ZQDTLTiVlgpUbzqLqKsbTea56hehqDi25OYYFCylIJKblNiWdnmhaaIDrbQlySMYEwlyvBCM+mIze6HodlT2PnrnzCJdpiMZsRa3WMHoTQ2+p4V+nt+pbQ5RhLxqDQXxpPQkmrZvk6NvXNRjU0ukfvRCuQwQr17DTXotqHcGYgKENQSpUYTCLAiqhC4+QzD7sH51i8yvThPREwUHLBO3SBMSt3sVQeI8gtPiKUELLAlV7QWm9A73E4fk5PxeiUNWfWqdapIUO+IcAPyQ= X-MS-TrafficTypeDiagnostic: DB8EUR05HT119: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /DVE/zHiX3LUu108qZXKWUoSSjIhQCxQTTi+ZVZQZrRRpCuzELqJ+cF3IWcNnlaQQ7Te5GrJApFnRSF0hIq/07B/bEenFnSIj1a6d6KRazhrxiTQEsuB3zt2KCcoe4WTj29PlNiXo4fjdry45teSQHaMoni5hbI1/Y9y3JhkyvzvX+HLlL5Ix9/U2qQwU4S9p8mAxVDTQpTowr6pSZP4FMCwL5k68WG53r/P8+TCwD2lbfe2HBVDbOpO+hWRE6G85wIqc0ekHK2Y2oYJBd54oISyEbm7qqiecCA/dQm2ROnKrydO7NYfleBxs1Dd3EP3dp3P/uK2qOA89n21dIBY930YmwumCxz5nCk0k1QvR4fxo3bb6qoq0BZc4bW8yYOD1ZrNWEQgYDKrr3pUyhagtA== X-MS-Exchange-AntiSpam-MessageData: iyqOVKKK9b/Z1MkJE7xulDYwM2Ksx1IK9X8ISEq7DWL0eU57TgdSxcNyVXsB+R3+j0G26huO+1UyNb97DlXEhrao2OxZ0fT3cIsp5rqHQDJebSB5ZZnAPsLjMbSWahNn4jKBWw07awJXU5FLHvBDqg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f24dbaa1-c112-49e1-f87c-08d93056043e X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jun 2021 23:33:44.8371 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB8EUR05FT030.eop-eur05.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8EUR05HT119 Subject: [FFmpeg-devel] [PATCH 25/54] avformat/mov: Simplify cleanup after read_header failure 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: oCdJIYGzu7fA By default, a demuxer's read_close function is not called automatically if an error happens when reading the header; instead it is up to the demuxer to clean up after itself in this case. The mov demuxer did this by calling its read_close function when it encountered some errors when reading the header. This commit changes this by setting the FF_FMT_INIT_CLEANUP flag so that mov_read_close() is automatically called when an error happens when reading the header. (Btw: mov_read_close() is not idempotent: Calling it twice is dangerouos, because MOVContext.frag_index.item will be av_freep'ed, yet MOVContext.frag_index.nb_items won't be reset. So the calls to mov_read_close() have to be removed before the switch to freeing generically.) Signed-off-by: Andreas Rheinhardt --- libavformat/mov.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 47a8e41236..2e061a55d1 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7556,13 +7556,12 @@ static int mov_read_header(AVFormatContext *s) avio_seek(pb, 0, SEEK_SET); if ((err = mov_read_default(mov, pb, atom)) < 0) { av_log(s, AV_LOG_ERROR, "error reading header\n"); - goto fail; + return err; } } while ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mov->found_moov && !mov->moov_retry++); if (!mov->found_moov) { av_log(s, AV_LOG_ERROR, "moov atom not found\n"); - err = AVERROR_INVALIDDATA; - goto fail; + return AVERROR_INVALIDDATA; } av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb)); @@ -7616,7 +7615,7 @@ static int mov_read_header(AVFormatContext *s) } if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) { if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0) - goto fail; + return err; } } if (mov->handbrake_version && @@ -7635,8 +7634,7 @@ static int mov_read_header(AVFormatContext *s) if (sc->data_size > INT64_MAX / sc->time_scale / 8) { av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %"PRId64" * 8 * %d\n", sc->data_size, sc->time_scale); - err = AVERROR_INVALIDDATA; - goto fail; + return AVERROR_INVALIDDATA; } st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / st->duration; } @@ -7651,8 +7649,7 @@ static int mov_read_header(AVFormatContext *s) if (sc->data_size > INT64_MAX / sc->time_scale / 8) { av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %"PRId64" * 8 * %d\n", sc->data_size, sc->time_scale); - err = AVERROR_INVALIDDATA; - goto fail; + return AVERROR_INVALIDDATA; } st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / sc->duration_for_fps; @@ -7676,14 +7673,14 @@ static int mov_read_header(AVFormatContext *s) case AVMEDIA_TYPE_AUDIO: err = ff_replaygain_export(st, s->metadata); if (err < 0) - goto fail; + return err; break; case AVMEDIA_TYPE_VIDEO: if (sc->display_matrix) { err = av_stream_add_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, (uint8_t*)sc->display_matrix, sizeof(int32_t) * 9); if (err < 0) - goto fail; + return err; sc->display_matrix = NULL; } @@ -7692,7 +7689,7 @@ static int mov_read_header(AVFormatContext *s) (uint8_t *)sc->stereo3d, sizeof(*sc->stereo3d)); if (err < 0) - goto fail; + return err; sc->stereo3d = NULL; } @@ -7701,7 +7698,7 @@ static int mov_read_header(AVFormatContext *s) (uint8_t *)sc->spherical, sc->spherical_size); if (err < 0) - goto fail; + return err; sc->spherical = NULL; } @@ -7710,7 +7707,7 @@ static int mov_read_header(AVFormatContext *s) (uint8_t *)sc->mastering, sizeof(*sc->mastering)); if (err < 0) - goto fail; + return err; sc->mastering = NULL; } @@ -7719,7 +7716,7 @@ static int mov_read_header(AVFormatContext *s) (uint8_t *)sc->coll, sc->coll_size); if (err < 0) - goto fail; + return err; sc->coll = NULL; } @@ -7733,9 +7730,6 @@ static int mov_read_header(AVFormatContext *s) mov->frag_index.item[i].headers_read = 1; return 0; -fail: - mov_read_close(s); - return err; } static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) @@ -8205,6 +8199,7 @@ const AVInputFormat ff_mov_demuxer = { .priv_class = &mov_class, .priv_data_size = sizeof(MOVContext), .extensions = "mov,mp4,m4a,3gp,3g2,mj2,psp,m4b,ism,ismv,isma,f4v", + .flags_internal = FF_FMT_INIT_CLEANUP, .read_probe = mov_probe, .read_header = mov_read_header, .read_packet = mov_read_packet,