From patchwork Mon Apr 5 01:28:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26740 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 695D344BBD9 for ; Mon, 5 Apr 2021 04:29:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 46659687F71; Mon, 5 Apr 2021 04:29:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2078.outbound.protection.outlook.com [40.92.89.78]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 084E6687F71 for ; Mon, 5 Apr 2021 04:29:11 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lU9yGja3e00Eb9jUX6PSHM7mG77qOQ9POcBu40+TCA8sgJIhog9xKyewuiOcK07rIqwhGNDYJIHcGaV8Z8Pmz2DXxJIOUH4CZkxVOYoZES7uzdf8NLAhHOps4mTe8mkIsqyo9UEaJZcRqHaM6pfNE6pANx9KDZghf0Z0mHi749e0AvPw/uQ2SqrNtPHsLTdbYL87vw8X931WPiwED6gqBbF4SDZDozDY9IUMaMxB0ZDpAtaxTgHOq1PShNzqIaotwiTEcwaQe0ug37UkP+DVJWEVhP4Y7Y95/od8QkubzxwPWDmqQyEceJmDhjImwUjGWHIiVDNieIH3kJjWOADZdw== 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=0etH2wmUd1r3gclNRhLOp9yT/gX5G/4Y1+Rj1iVk5ys=; b=GPpdgmSiG02A47mxEFYQMyCJnHQVeOjXQiHGhBp53G0nouwWEp/PWZT0D+oidXRGUAOGFKI518QbZlBDBjZgx6v+DrNexwIeAZkV3YflHKcFyg+WuOwJwULIFRv/3j6gK7/uKOPhOYiVmVzdvi1oljxR8AulsZneGYDK3JiMUUOTf1wcm5qUJ7A3ZqQyr47Bo4FJxaAnNv8Ih6vAGDnnkZZh04im7bQJMv5JhfeywUoEDvePWJYXNQsZ21Gv5AoxgiTLhjf757cFe/myQK89TjImIQA7YQgENpMDY52SP8hjW5c7iiSGbCilMvyiH3/oD+qfSERTpHO95TSKdohnWA== 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=0etH2wmUd1r3gclNRhLOp9yT/gX5G/4Y1+Rj1iVk5ys=; b=aWFmnQ9Qfh8OdtzQRF8aVL2XyCkYK2DwKdoXfhCmrURD+mdmL5CGOaF2OTVkswMbXi03u7L5qw2z3AvR9Cqk564voiVmPjEidzynaCLeLlDTOAhzKhBYVmt+xRsvjYZaYslU6ftN8cA4+upnv+wNZO60GNMa7QfYQdPgOYk2L066OmkSd7nt+ICQPM3o8VFh9lm6HDCyXjyvLSWa+nb41qiaTWgw4xRly5pHLeUg+Uzr+hv5ZtDLwD9BVHEU0kKwev/AzPP/JmU0vkgDlTvJoC3cZFiIFXSvNqIhcrO9Jb/HsNsYbeiGrhe64sFLduOWim+q0QXX+vaTnczzQjHPyA== Received: from DB8EUR05FT020.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc0f::40) by DB8EUR05HT040.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc0f::119) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Mon, 5 Apr 2021 01:29:10 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:fc0f::53) by DB8EUR05FT020.mail.protection.outlook.com (2a01:111:e400:fc0f::136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 01:29:10 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:4A10FDB00D0C8F88C84BB6ABE517A37CBBE02345BFC9F5E435CAEA74740D7D3E; UpperCasedChecksum:CE075AEA0FEB1695EDF6D41736CFBE5537F6861F97C705E3D3147E926898FF72; SizeAsReceived:7433; Count:46 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 01:29:09 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Apr 2021 03:28:52 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 X-TMN: [97UGvYBWIfGyzuT1ZLpSivou0P61FVv2] X-ClientProxiedBy: AM0PR02CA0024.eurprd02.prod.outlook.com (2603:10a6:208:3e::37) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210405012857.3973452-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM0PR02CA0024.eurprd02.prod.outlook.com (2603:10a6:208:3e::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 01:29:08 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 108b6a65-473e-4e6a-680b-08d8f7d235c4 X-MS-TrafficTypeDiagnostic: DB8EUR05HT040: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hU3itLrRiCoQIE+Vn6pgPGo9FaHk+F48JY/jHpwqQAwEKDqTwJJmuqmti6JmyaLCZXisEIATIpVCUUEHZuhDadol5CYOIjTu3666zCEJ/yzsD5zl+O06zh5o4c8bPqKFCXU1pqwO9NqSQA1dJIVymawMA7R1JyfloKCPRjYOp1MDo3Zkt/iwB1ypit8oBnQAqBs3UPSiKaEIf+09SygD2KAcKNQ86fANXxelwpsYnIdQC4dtVuXCMl1nBGLvQxKnobnX7scsivbaYol5la+8gcBgeHKHh+1daegXXQf+0ocgw7a5/umlHT9QOHVb8IJAsZ0oxE4zPB0LDaDNBdBmfgaVZKbbj9YEGdEP6qOh3RTk2ATRFtG8BouNWmteVbsA7sErkV8dDtZLcd2VkwEPTQ== X-MS-Exchange-AntiSpam-MessageData: L6DVONaAuW19VuLWbCUqMbHLamD8gw3Rgs8SeCon6dRhLiReqHeocM5/mdBYZL3CUorq30YkE68abKw3krhmwBhZIO4XUZcZbrcKkAA84UDWZi0fhHU/czHntDOd706xi4QCV2V9KtuSV0VRdfnScg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 108b6a65-473e-4e6a-680b-08d8f7d235c4 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 01:29:09.2930 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB8EUR05FT020.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: DB8EUR05HT040 Subject: [FFmpeg-devel] [PATCH 1/6] Revert "avcodec: add FF_CODEC_CAP_INIT_CLEANUP for all codecs which use ff_mpv_common_init()" 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" From: Andreas Rheinhardt This mostly reverts commit 4b2863ff01b1fe93d9a518523c9098d17a9d8c6f. Said commit removed the freeing code from ff_mpv_common_init(), ff_mpv_common_frame_size_change() and ff_mpeg_framesize_alloc() and instead added the FF_CODEC_CAP_INIT_CLEANUP to several codecs that use ff_mpv_common_init(). This introduced several bugs: a) Several decoders using ff_mpv_common_init() in their init function were forgotten: This affected FLV, Intel H.263, RealVideo 3.0 and V4.0 as well as VC-1/WMV3. b) ff_mpv_common_init() is not only called from the init function of codecs, it is also called from AVCodec.decode functions. If an error happens after an allocation has succeeded, it can lead to memleaks; furthermore, it is now possible for the MpegEncContext to be marked as initialized even when ff_mpv_common_init() returns an error and this can lead to segfaults because decoders that call ff_mpv_common_init() when decoding a frame can mistakenly think that the MpegEncContext has been properly initialized. This can e.g. happen with H.261 or MPEG-4. c) Removing code for freeing from ff_mpeg_framesize_alloc() (which can't be called from any init function) can lead to segfaults because the check for whether it needs to allocate consists of checking whether the first of the buffers allocated there has been allocated. This part has already been fixed in 76cea1d2ce3f23e8131c8664086a1daf873ed694. d) ff_mpv_common_frame_size_change() can also not be reached from any AVCodec.init function; yet the changes can e.g. lead to segfaults with decoders using ff_h263_decode_frame() upon allocation failure, because the MpegEncContext will upon return be flagged as both initialized and not in need of reinitialization (granted, the fact that ff_h263_decode_frame() clears context_reinit before the context has been reinited is a bug in itself). With the earlier version, the context would be cleaned upon failure and it would be attempted to initialize the context again in the next call to ff_h263_decode_frame(). While a) could be fixed by adding the missing FF_CODEC_CAP_INIT_CLEANUP, keeping the current approach would entail adding cleanup code to several other places because of b). Therefore ff_mpv_common_init() is again made to clean up after itself; the changes to the wmv2 decoder and the SVQ1 encoder have not been reverted: The former fixed a memleak, the latter allowed to remove cleanup code. Signed-off-by: Andreas Rheinhardt --- libavcodec/h261dec.c | 2 +- libavcodec/h263dec.c | 4 ++-- libavcodec/mpeg12dec.c | 9 +++++---- libavcodec/mpeg4videodec.c | 3 +-- libavcodec/mpegvideo.c | 31 ++++++++++++++++++++----------- libavcodec/msmpeg4dec.c | 8 ++++---- libavcodec/rv10.c | 2 -- 7 files changed, 33 insertions(+), 26 deletions(-) diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c index 5c25aa9cb3..eb544e6046 100644 --- a/libavcodec/h261dec.c +++ b/libavcodec/h261dec.c @@ -678,6 +678,6 @@ AVCodec ff_h261_decoder = { .close = h261_decode_end, .decode = h261_decode_frame, .capabilities = AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, .max_lowres = 3, }; diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index dafa54d8d4..e8b4d83e6e 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -771,7 +771,7 @@ AVCodec ff_h263_decoder = { .decode = ff_h263_decode_frame, .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .flush = ff_mpeg_flush, .max_lowres = 3, .pix_fmts = ff_h263_hwaccel_pixfmt_list_420, @@ -789,7 +789,7 @@ AVCodec ff_h263p_decoder = { .decode = ff_h263_decode_frame, .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .flush = ff_mpeg_flush, .max_lowres = 3, .pix_fmts = ff_h263_hwaccel_pixfmt_list_420, diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 92dd6a0b24..94221da2c1 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -2880,7 +2880,8 @@ static av_cold int mpeg_decode_end(AVCodecContext *avctx) { Mpeg1Context *s = avctx->priv_data; - ff_mpv_common_end(&s->mpeg_enc_ctx); + if (s->mpeg_enc_ctx_allocated) + ff_mpv_common_end(&s->mpeg_enc_ctx); av_buffer_unref(&s->a53_buf_ref); return 0; } @@ -2897,7 +2898,7 @@ AVCodec ff_mpeg1video_decoder = { .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS, - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP | + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .flush = flush, .max_lowres = 3, @@ -2931,7 +2932,7 @@ AVCodec ff_mpeg2video_decoder = { .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS, - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP | + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .flush = flush, .max_lowres = 3, @@ -2976,7 +2977,7 @@ AVCodec ff_mpegvideo_decoder = { .close = mpeg_decode_end, .decode = mpeg_decode_frame, .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS, - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP | + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .flush = flush, .max_lowres = 3, diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index 2ca804fdc6..2c440a5026 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -3579,8 +3579,7 @@ AVCodec ff_mpeg4_decoder = { AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_FRAME_THREADS, .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | - FF_CODEC_CAP_ALLOCATE_PROGRESS | - FF_CODEC_CAP_INIT_CLEANUP, + FF_CODEC_CAP_ALLOCATE_PROGRESS, .flush = ff_mpeg_flush, .max_lowres = 3, .pix_fmts = ff_h263_hwaccel_pixfmt_list_420, diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 728e591958..2351a09874 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -932,17 +932,17 @@ av_cold int ff_mpv_common_init(MpegEncContext *s) for (i = 0; i < MAX_PICTURE_COUNT; i++) { s->picture[i].f = av_frame_alloc(); if (!s->picture[i].f) - return AVERROR(ENOMEM); + goto fail_nomem; } if (!(s->next_picture.f = av_frame_alloc()) || !(s->last_picture.f = av_frame_alloc()) || !(s->current_picture.f = av_frame_alloc()) || !(s->new_picture.f = av_frame_alloc())) - return AVERROR(ENOMEM); + goto fail_nomem; if ((ret = init_context_frame(s))) - return AVERROR(ENOMEM); + goto fail; s->parse_context.state = -1; @@ -956,10 +956,10 @@ av_cold int ff_mpv_common_init(MpegEncContext *s) if (i) { s->thread_context[i] = av_memdup(s, sizeof(MpegEncContext)); if (!s->thread_context[i]) - return AVERROR(ENOMEM); + goto fail_nomem; } if ((ret = init_duplicate_context(s->thread_context[i])) < 0) - return ret; + goto fail; s->thread_context[i]->start_mb_y = (s->mb_height * (i) + nb_slices / 2) / nb_slices; s->thread_context[i]->end_mb_y = @@ -967,7 +967,7 @@ av_cold int ff_mpv_common_init(MpegEncContext *s) } } else { if ((ret = init_duplicate_context(s)) < 0) - return ret; + goto fail; s->start_mb_y = 0; s->end_mb_y = s->mb_height; } @@ -975,6 +975,11 @@ av_cold int ff_mpv_common_init(MpegEncContext *s) // } return 0; + fail_nomem: + ret = AVERROR(ENOMEM); + fail: + ff_mpv_common_end(s); + return ret; } /** @@ -1067,7 +1072,7 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) if ((s->width || s->height) && (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0) - return err; + goto fail; /* set chroma shifts */ err = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, @@ -1077,7 +1082,7 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) return err; if ((err = init_context_frame(s))) - return err; + goto fail; memset(s->thread_context, 0, sizeof(s->thread_context)); s->thread_context[0] = s; @@ -1089,11 +1094,12 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) if (i) { s->thread_context[i] = av_memdup(s, sizeof(MpegEncContext)); if (!s->thread_context[i]) { - return AVERROR(ENOMEM); + err = AVERROR(ENOMEM); + goto fail; } } if ((err = init_duplicate_context(s->thread_context[i])) < 0) - return err; + goto fail; s->thread_context[i]->start_mb_y = (s->mb_height * (i) + nb_slices / 2) / nb_slices; s->thread_context[i]->end_mb_y = @@ -1102,7 +1108,7 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) } else { err = init_duplicate_context(s); if (err < 0) - return err; + goto fail; s->start_mb_y = 0; s->end_mb_y = s->mb_height; } @@ -1110,6 +1116,9 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) } return 0; + fail: + ff_mpv_common_end(s); + return err; } /* init common structure for both encoder and decoder */ diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c index 405fda4b83..63f9faa1bb 100644 --- a/libavcodec/msmpeg4dec.c +++ b/libavcodec/msmpeg4dec.c @@ -870,7 +870,7 @@ AVCodec ff_msmpeg4v1_decoder = { .close = ff_h263_decode_end, .decode = ff_h263_decode_frame, .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .max_lowres = 3, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, @@ -888,7 +888,7 @@ AVCodec ff_msmpeg4v2_decoder = { .close = ff_h263_decode_end, .decode = ff_h263_decode_frame, .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .max_lowres = 3, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, @@ -906,7 +906,7 @@ AVCodec ff_msmpeg4v3_decoder = { .close = ff_h263_decode_end, .decode = ff_h263_decode_frame, .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .max_lowres = 3, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, @@ -924,7 +924,7 @@ AVCodec ff_wmv1_decoder = { .close = ff_h263_decode_end, .decode = ff_h263_decode_frame, .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .max_lowres = 3, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index d5c7480611..89b838ad15 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -687,7 +687,6 @@ AVCodec ff_rv10_decoder = { .close = rv10_decode_end, .decode = rv10_decode_frame, .capabilities = AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, .max_lowres = 3, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, @@ -705,7 +704,6 @@ AVCodec ff_rv20_decoder = { .close = rv10_decode_end, .decode = rv10_decode_frame, .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, .flush = ff_mpeg_flush, .max_lowres = 3, .pix_fmts = (const enum AVPixelFormat[]) { From patchwork Mon Apr 5 01:44:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26741 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 C04254481E1 for ; Mon, 5 Apr 2021 04:44:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 98D0E687FBB; Mon, 5 Apr 2021 04:44:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR06-VI1-obe.outbound.protection.outlook.com (mail-vi1eur06olkn2025.outbound.protection.outlook.com [40.92.17.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9D095687FBB for ; Mon, 5 Apr 2021 04:44:43 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mdfy59D6gzx9Qlwb/yCDTlJhjAU+FPCrdiXZOvlSChJV9Wxu0zqQILOI9YqztxIo+iNzyaSDXFUTrMyk/Mbgs5cd3AkP/V2Re3UYtjjq8xSlR6svWFECSw61jSGzjLLasyt1PiOFlPQSNhL/a2y36Jox/RSeUb33aTtbnzA5S0TQMGalhdN98TD2wbMfpTYXd/cT7cd4ccNGZWotxP/NY//rv0H0rm2IdZiDcS0KjLdZmevyKxMPi8MIkbqWdQTy9xeDey//4OAzlxjrSYWouiByWDEY7dt9eVERbroMjN/xFTbfZwPmNd9Qj1IzvFSjXHzZNzdvCksVAo/6+xGdLA== 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=sTr4mY643T0L9DuHOzQGt3cx6gb/UkkigUMYGFGH2ms=; b=NQxQtElSjxT6TUr+VofSZKXH+C9V1oV3kRFtQXgsQXIhFf3lUm9WJSLT/LFj/in9rUkRKriGMRFpI8oUEHFgFYHuvPINyFaoEmhxz8v4bqPgABFPd96+nj10ergq6jnss6y/mffYP2Mooed3XolvQJdr2ANMIljmFlbNwaSQUlGsPOExchY4sq3Z3i5458htcMVEuDlgMFarGYFHwsOZ5XS8uZlRnwM3IVv+zsQqDMeABFd8QbPyyoPNeRh2dJxi5AAuyWqq9t0wkOADHGtrAoCuQ+VaXP0UZ37iN67PEnZfBPz2xbZyjY9er3P7YACx6j4N04gKNLIEIdkFaglj7g== 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=sTr4mY643T0L9DuHOzQGt3cx6gb/UkkigUMYGFGH2ms=; b=nOIr0MzPajgndl6RLNe/N1ZGV59Cv9zWEsBZKd59FirmZIdiX5nBDKJHcSzQZinmeIyi0snTcg1M7eobHjf+9FJUH2o+9BpmIcP3cCROkIqM64fwn3mXC24sEZZS+egiNHRI6Ce/eJWI5D1+evJHXGGl5ibu38O9KYYJTdgCvBejiFXhXib9WVnDFxFeOuoo2u225MnsWJMif+teC/m5/hsUGo0YY81qeW32+F5eYSsjq6YuRYUnCzcXuNeWpsnZOZqqxML4O/VHpVnP7f6R9XPGaodN51Mr6S4WtdSjXlgy+9ypUDRAko9/FKmXzyC3bBht8YKFEJ0BQvqMH/7Qgw== Received: from AM7EUR06FT063.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::4b) by AM7EUR06HT025.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Mon, 5 Apr 2021 01:44:42 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:fc36::52) by AM7EUR06FT063.mail.protection.outlook.com (2a01:111:e400:fc36::403) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 01:44:42 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:0F384152DE747CCEB13776E6931A867B176A3CDC8A5954025661B8F6E27C6611; UpperCasedChecksum:50EB8DCD41946C455705EEB41249D4DC3E744E201DBC3B1667ACF1D28544237E; SizeAsReceived:7591; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 01:44:41 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Apr 2021 03:44:30 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [59JWNkDO2VkPSHJ47xSRiKYxGKPItWcZ] X-ClientProxiedBy: AM0PR02CA0189.eurprd02.prod.outlook.com (2603:10a6:20b:28e::26) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210405014434.3973535-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM0PR02CA0189.eurprd02.prod.outlook.com (2603:10a6:20b:28e::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 01:44:41 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 8feb461c-a0b9-4426-d20e-08d8f7d46187 X-MS-TrafficTypeDiagnostic: AM7EUR06HT025: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LhKiZ1/OTKZOnqTWn7jhG1fFMwwLLvQlLq+x/yJbOrKKOn82aFz0Ef8GtnVu3CUguJS6nFFwh30fY5sM4HdpuXoHbTKAon/RtVg445k9eJQvgLAPE2vLnTx6K5nxOLIJVQlwrLH+ZyEKc7+k9SiFACfNzMZEgQfMpL1/LP1H9KlD3A96LFe9IrfS7GLPnk6kSUnDTR0nvS6g3mnM9EPauspJuWje8cgNK1DVO4Nl8tonL3lKeEy52+Yepz3xZ0/VCFJGEsUUoj3MyKpl12xgPAAH8u9Z1r9MPx8mutCLgfzzxPt+dHysjDLwlVjbaUIEVTGcGZyhdix+x6XksJh9j2EjNZ5QyMEcd3aGme+HPSMmtMV/ErBMMR84Y2RnE0jm X-MS-Exchange-AntiSpam-MessageData: JUkfkFd01W324/cJflFEdCduGFys8jApPWBGKhRLLyJypqsT5ugmM2Fy4oC8bocsqhmk4sy2mvp0Km2bcBv8sxnMxxyZSelW/m0UCqCt6p1lGGgWxTRLWJiyy97IgESN8wYjfip3+bB0sql0B+kPBw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8feb461c-a0b9-4426-d20e-08d8f7d46187 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 01:44:41.6222 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT063.eop-eur06.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: AM7EUR06HT025 Subject: [FFmpeg-devel] [PATCH 2/6] avcodec/mpegvideo: Fix memleak upon 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" From: Andreas Rheinhardt When slice-threading is used, ff_mpv_common_init() duplicates the first MpegEncContext and allocates some buffers for each MpegEncContext (the first as well as the copies). But the count of allocated MpegEncContexts is not updated until after everything has been allocated and if an error happens after the first one has been allocated, only the first one is freed; the others leak. This commit fixes this: The count is now set before the copies are allocated. Furthermore, the copies are now created and initialized before the first MpegEncContext, so that the buffers exclusively owned by each MpegEncContext are still NULL in the src MpegEncContext so that no double-free happens upon allocation failure. Given that this effectively touches every line of the init code, it has also been factored out in a function of its own in order to remove code duplication with the same code in ff_mpv_common_frame_size_change() (which was never called when using more than one slice (and if it were, there would be potential double-frees)). Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.c | 91 +++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 54 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 2351a09874..7327204e99 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -366,13 +366,6 @@ static int init_duplicate_context(MpegEncContext *s) if (s->mb_height & 1) yc_size += 2*s->b8_stride + 2*s->mb_stride; - s->sc.edge_emu_buffer = - s->me.scratchpad = - s->me.temp = - s->sc.rd_scratchpad = - s->sc.b_scratchpad = - s->sc.obmc_scratchpad = NULL; - if (s->encoding) { if (!FF_ALLOCZ_TYPED_ARRAY(s->me.map, ME_MAP_SIZE) || !FF_ALLOCZ_TYPED_ARRAY(s->me.score_map, ME_MAP_SIZE)) @@ -413,6 +406,35 @@ static int init_duplicate_context(MpegEncContext *s) return 0; } +/** + * Initialize an MpegEncContext's thread contexts. Presumes that + * slice_context_count is already set and that all the fields + * that are freed/reset in free_duplicate_context() are NULL. + */ +static int init_duplicate_contexts(MpegEncContext *s) +{ + int nb_slices = s->slice_context_count, ret; + + /* We initialize the copies before the original so that + * fields allocated in init_duplicate_context are NULL after + * copying. This prevents double-frees upon allocation error. */ + for (int i = 1; i < nb_slices; i++) { + s->thread_context[i] = av_memdup(s, sizeof(MpegEncContext)); + if (!s->thread_context[i]) + return AVERROR(ENOMEM); + if ((ret = init_duplicate_context(s->thread_context[i])) < 0) + return ret; + s->thread_context[i]->start_mb_y = + (s->mb_height * (i ) + nb_slices / 2) / nb_slices; + s->thread_context[i]->end_mb_y = + (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices; + } + s->start_mb_y = 0; + s->end_mb_y = nb_slices > 1 ? (s->mb_height + nb_slices / 2) / nb_slices + : s->mb_height; + return init_duplicate_context(s); +} + static void free_duplicate_context(MpegEncContext *s) { if (!s) @@ -949,29 +971,12 @@ av_cold int ff_mpv_common_init(MpegEncContext *s) s->context_initialized = 1; memset(s->thread_context, 0, sizeof(s->thread_context)); s->thread_context[0] = s; + s->slice_context_count = nb_slices; // if (s->width && s->height) { - if (nb_slices > 1) { - for (i = 0; i < nb_slices; i++) { - if (i) { - s->thread_context[i] = av_memdup(s, sizeof(MpegEncContext)); - if (!s->thread_context[i]) - goto fail_nomem; - } - if ((ret = init_duplicate_context(s->thread_context[i])) < 0) - goto fail; - s->thread_context[i]->start_mb_y = - (s->mb_height * (i) + nb_slices / 2) / nb_slices; - s->thread_context[i]->end_mb_y = - (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices; - } - } else { - if ((ret = init_duplicate_context(s)) < 0) - goto fail; - s->start_mb_y = 0; - s->end_mb_y = s->mb_height; - } - s->slice_context_count = nb_slices; + ret = init_duplicate_contexts(s); + if (ret < 0) + goto fail; // } return 0; @@ -1079,7 +1084,7 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) &s->chroma_x_shift, &s->chroma_y_shift); if (err < 0) - return err; + goto fail; if ((err = init_context_frame(s))) goto fail; @@ -1088,31 +1093,9 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) s->thread_context[0] = s; if (s->width && s->height) { - int nb_slices = s->slice_context_count; - if (nb_slices > 1) { - for (i = 0; i < nb_slices; i++) { - if (i) { - s->thread_context[i] = av_memdup(s, sizeof(MpegEncContext)); - if (!s->thread_context[i]) { - err = AVERROR(ENOMEM); - goto fail; - } - } - if ((err = init_duplicate_context(s->thread_context[i])) < 0) - goto fail; - s->thread_context[i]->start_mb_y = - (s->mb_height * (i) + nb_slices / 2) / nb_slices; - s->thread_context[i]->end_mb_y = - (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices; - } - } else { - err = init_duplicate_context(s); - if (err < 0) - goto fail; - s->start_mb_y = 0; - s->end_mb_y = s->mb_height; - } - s->slice_context_count = nb_slices; + err = init_duplicate_contexts(s); + if (err < 0) + goto fail; } return 0; From patchwork Mon Apr 5 01:44:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26742 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 B22B444982B for ; Mon, 5 Apr 2021 04:45:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8EB61688126; Mon, 5 Apr 2021 04:45:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR06-AM7-obe.outbound.protection.outlook.com (mail-am7eur06olkn2015.outbound.protection.outlook.com [40.92.16.15]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E4F9F687EC8 for ; Mon, 5 Apr 2021 04:44:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a427bDSD4pCVcpdq/3r7f4Jzj9faHpHvckS1sv9UZUE6ekaOnVxHpNHeF0xVsh7IAfU09a36Fclv4wdliM5YL+BOI/mrpPsIVhRCrunbPHX7b8IUZOgTPPa1kwiFNu0IH5sGEDLA461nrgqpDWW1fUHpbloJpDFxK0CRknRIXFrodUuqmAPSx+0DZ25XBL8WVu/GlyI3N18z+mcWdh0h+8X0JwiPt6OQT/bBPe1ZV8oEkwUyW5GZuMgp+5wsstgtF4kf8BMlcfchygNVb6EYoghwrAI8OjTisYF+qrnDS6VO6vSYSMk5/GhL8dyq0sBxsov8kahXeML7lrAa3+aZLA== 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=FZX4ujOZ7fG9asu5LgYigZbzTCQvdWYJ03TgVqvJMc4=; b=ln+da5+UBqJpbVZuw9tWzUkRqySFDC+OgIYy4lvaqwehWRgAPZUoR3p9wk89X/CIiyt0f/IeOaTEJLkbVBhgMwEk1CWkL56XxmLaIYshD+R5XBtLPZywDPklVGLnUuqXM8+ejSjgyn4Gm6/qbJsaeXf2J5Uw7n8mqZ7RpEXl/EfKbjWHiUX12VV7WQbddVAZvRQY2zWyTfJOTEOOcYfcXzTim4JTptDdmZ0QiLnQ7yiJjK9VUjeC8NJsg5Pvb1eO8uwrKa68aVnIyFk9LwE7ghalu9lqGF4uWHx/nMuIEmZVMAMNGT+ptvKg0BtEPKJlCVJ0eWcUftCwWL7/2t2c6g== 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=FZX4ujOZ7fG9asu5LgYigZbzTCQvdWYJ03TgVqvJMc4=; b=J5ig+WOREf4wERE205SB665XQRvPExcI4nczffCymRpi67RsFxmtg1OysUKq6gnHLqpomRTSYuHKkegljk8MSO7Ckoa369X8NTeuSWEZI6PeEaCDsKGLWZmUQnOq4Xgi50KMRHcVbMfPNPd2v8a6L/XOBo02P1p0gdkhSjlVQSEcepK/keTUljfxrMXwM7hdIGYYBxDOIctV2aOaJrbhjOrpKNQ8tvazsBy8Wa2oxrVcLkgD7ohtPoZKtzMIRqdM2J/SM8D7ll7VgXj+gOjfAqdsuwSElmHydsXP2fL9xEVBLN+xcnFJmnN24xzKuYe2JepgXnNrnHyZHa+AHuJJGA== Received: from AM7EUR06FT063.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::48) by AM7EUR06HT232.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::345) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Mon, 5 Apr 2021 01:44:58 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:fc36::52) by AM7EUR06FT063.mail.protection.outlook.com (2a01:111:e400:fc36::403) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 01:44:58 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:13702BA36D4E1F768C159D71F1B986A2805AA65F4F168E49EEA41B115752A4B8; UpperCasedChecksum:B0F012CF64049DDC906369E4ED471B1C36963057888F4749AEBE8900EE10C493; SizeAsReceived:7606; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 01:44:58 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Apr 2021 03:44:31 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [GSsBZEZVahS26tftBYzQDDAnIvyt7KUo] X-ClientProxiedBy: AM0PR02CA0189.eurprd02.prod.outlook.com (2603:10a6:20b:28e::26) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210405014434.3973535-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM0PR02CA0189.eurprd02.prod.outlook.com (2603:10a6:20b:28e::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 01:44:57 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 5286e57c-b382-4c5b-c0d0-08d8f7d46b9e X-MS-TrafficTypeDiagnostic: AM7EUR06HT232: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vAJ7gLvbB7kz1vdGuigh/6h4sxAr/EjBhtZS/SjR0nqA5TL0aELbgfmMngRk0dWhh4piXnnOE3IxUZ7kcHzkTv+EcnOFo+5wRjvopPEgVE0V+bnp5qqSHW1lk3ORTTxJHfXpV52O4B7SMTGhL0uqrRcqsatGqVzklCbvlClIkkV/QzY+gnU40ejI312RX5xL8hndJR+8N1DSXE5li14FvcOG4Pwucz0XSoDEh6DEFC6T2aGDNr627f16RiHbGk+1GGpI9LuTQxIh2jUOsigc3Jq/Db0vNieI46i6oAKSqDnFqy4WuZrFuSrgU2WIW/kRiAX0QPggRfMFH4QntzjtXZLZRxPoVrcvBqzTLRY6QAHRDQHX9VeC3GC15FpCX8JOjWHThNmjJkCcrUCrLHZDvw== X-MS-Exchange-AntiSpam-MessageData: ahkmqzGyfDubtWQFVzwZFwHBgXSKWBLPRG1si9MIudHlD2jXCLX+ngEa1xg0zW34fRLYgtIrbpjCh8ghRGZql+tPWbcvx/VnjRhUB0vsJ0ElpDYee+Ycay7C8uAZ2kIjvKDbP0tCtZeAK3jPKfpDSg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5286e57c-b382-4c5b-c0d0-08d8f7d46b9e X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 01:44:58.5238 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT063.eop-eur06.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: AM7EUR06HT232 Subject: [FFmpeg-devel] [PATCH 3/6] avcodec/mpegvideo: Factor common freeing code out 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" From: Andreas Rheinhardt Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 7327204e99..7eddbdcc37 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -457,6 +457,15 @@ static void free_duplicate_context(MpegEncContext *s) s->block = NULL; } +static void free_duplicate_contexts(MpegEncContext *s) +{ + for (int i = 1; i < s->slice_context_count; i++) { + free_duplicate_context(s->thread_context[i]); + av_freep(&s->thread_context[i]); + } + free_duplicate_context(s); +} + static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src) { #define COPY(a) bak->a = src->a @@ -988,7 +997,8 @@ av_cold int ff_mpv_common_init(MpegEncContext *s) } /** - * Frees and resets MpegEncContext fields depending on the resolution. + * Frees and resets MpegEncContext fields depending on the resolution + * as well as the slice thread contexts. * Is used during resolution changes to avoid a full reinitialization of the * codec. */ @@ -996,6 +1006,8 @@ static void free_context_frame(MpegEncContext *s) { int i, j, k; + free_duplicate_contexts(s); + av_freep(&s->mb_type); av_freep(&s->p_mv_table_base); av_freep(&s->b_forw_mv_table_base); @@ -1048,16 +1060,6 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) if (!s->context_initialized) return AVERROR(EINVAL); - if (s->slice_context_count > 1) { - for (i = 0; i < s->slice_context_count; i++) { - free_duplicate_context(s->thread_context[i]); - } - for (i = 1; i < s->slice_context_count; i++) { - av_freep(&s->thread_context[i]); - } - } else - free_duplicate_context(s); - free_context_frame(s); if (s->picture) @@ -1112,15 +1114,9 @@ void ff_mpv_common_end(MpegEncContext *s) if (!s) return; - if (s->slice_context_count > 1) { - for (i = 0; i < s->slice_context_count; i++) { - free_duplicate_context(s->thread_context[i]); - } - for (i = 1; i < s->slice_context_count; i++) { - av_freep(&s->thread_context[i]); - } + free_context_frame(s); + if (s->slice_context_count > 1) s->slice_context_count = 1; - } else free_duplicate_context(s); av_freep(&s->parse_context.buffer); s->parse_context.buffer_size = 0; @@ -1152,8 +1148,6 @@ void ff_mpv_common_end(MpegEncContext *s) ff_mpeg_unref_picture(s->avctx, &s->new_picture); av_frame_free(&s->new_picture.f); - free_context_frame(s); - s->context_initialized = 0; s->last_picture_ptr = s->next_picture_ptr = From patchwork Mon Apr 5 01:44:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26743 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 C3C7D44982B for ; Mon, 5 Apr 2021 04:45:15 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A9C4668811C; Mon, 5 Apr 2021 04:45:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR06-AM7-obe.outbound.protection.outlook.com (mail-am7eur06olkn2025.outbound.protection.outlook.com [40.92.16.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7526C68803A for ; Mon, 5 Apr 2021 04:45:14 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MNj67FdnOqczumLB+SW1+GKyFLZhqnJHoB8IC13+0SH19AWkJFeas6dUS0sge+hnDNGFSeftVYijDJLJN8aV8z9RSMOYBpjPxPkd5HZehFrV7ZkEpxwzhbrt9rSAyY4qaOwlJOLyp5Slm9dKUDeLIfznavfToNqVhhvoi3+gvS5VyVja2f+Hm1qTBDNT0iuEuxoQtAi/FoILmnmp3mT8eVTOizcrHtV00VUXB44n6oUOf6+0uDqpxS8/5O/MKNXOWN+cxT/JtlWjMRO7FQEdPl4cAKnSvCytpPByO0GejlJIoOPhF2MtDqzY16t2slBB5qNTEWtFXt4hsjpRZR2mSQ== 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=2Nra4M+1P0oJPylR/eCFKL4DxnpFCenfCaSYtQ6PRQI=; b=ANHOTW4AXZyV3n5SSk0x98zZwSE/WVtA7RXLzu9jtqWhCKNSW/bZCwTXqMFLITUAgtMZcEMADo/O/SvEINxDi8JWHRtB+luSWBNbTMQ3IFyj7FOqv/mUbfmporG6Ylpvlq/MdNoerhqJIXVr1xXSmotmTRlSRuPpl+VbQHuF2QwOi32bs7ykThNzz0TeYMIWkWWQProNml3F8KioMlcjR0jFYp5msVwu8eUoQ3+KZCF/qP7bMoS0cOuysF24BtbOo5NHYIonAITrzvCRjBmfcFQ8Lj4NTopiVIZgKGFpxHnm/5ddpCajKnaEfhgjkh6W/3Vw0eLW2hc9RYhGUQzmdw== 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=2Nra4M+1P0oJPylR/eCFKL4DxnpFCenfCaSYtQ6PRQI=; b=oqoflDIY1kA6BF2+AckWuc7lA9T26PNwvqPp0H+R/6KN4c4Lce03w+VJAaaUzK6TI8GZdHBb4GcGPDhvnmn7goCCw5PhuZr/0/qu0PMAABsF+UUqOFz/YMUz+plcWrTvhzmRxhgmtPTx0i0aS80mACIPd97V65GXzYpOoDgFbqjH/x8qY8i1Wwv78yOiSIWACt9e/buY5UAFA0biIMeD5jfhgmQE+Io7LwDmFlexI4GSBGPEZN49ooq2BmKpaOPxfU2rPZyxqfm834rH2MSu1XiNpGort95aB505e83Jg1EW3cZ+oz3WCG/ZtWTpvriDc+wyPtpeg9fhU0r+KBmPQQ== Received: from AM7EUR06FT063.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::47) by AM7EUR06HT236.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::279) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Mon, 5 Apr 2021 01:45:13 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:fc36::52) by AM7EUR06FT063.mail.protection.outlook.com (2a01:111:e400:fc36::403) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 01:45:13 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:5B769E29BBD88E2AC9668769E791434B2EC5B8A4830ED69F77E88FAA9909E29D; UpperCasedChecksum:DBB4390700B5480D278DBA1C379FC786D9E09D306CE9C30534BF775FFAA4CF45; SizeAsReceived:7596; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 01:45:13 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Apr 2021 03:44:32 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [CuBLnYJlusRrzGfw2NkzQpGEKFHizwNH] X-ClientProxiedBy: AM0PR02CA0189.eurprd02.prod.outlook.com (2603:10a6:20b:28e::26) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210405014434.3973535-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM0PR02CA0189.eurprd02.prod.outlook.com (2603:10a6:20b:28e::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 01:45:12 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 0cca47d6-8cdb-4830-0995-08d8f7d47472 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiS3KLhuc01YFDN7B235wyuezd9HONY1KtCinqsFn3tOE7D1ScfzlzFfqP5GoQGF3WbCFeugYYjVLUi43JeZe/AUC0usW20SzSy7JS+yHtA8W2qcRQEhZoegccll/uqLRKvtL4+iiNFBCZLGgN56oatMGlPppomDOR+oAEWWirb/Ez8al6m4f8Bw/kq5YbeOZ1i0PH3J6ye1ysEVc+jr2pa3sXxbC7Ng2meK/G6Ajam99MVa6wJNDZA4Tiadubz5Now+bujASTvxeLzYNp0Djz3bu4FCet4fpBxEhbKIy+tMePhpdL/u70MG/imczt4wC8veQfFcOO/A665erUJ0GB4Wpm61EJt39EjEx1d9WUKx0puAsxnMmgJoC/p8T0F6bu0VUOBXWbznew/BCFpYb/VnWVygh3S2wNRXZH7UzDo2dSLcnFoHwWyIxBhgcKKu0zKA9XvEI6wUMA6xZivclC7KQYRDnZbYXlVrrItBnthHj1q0gnLdaijWakSPAB+RvowhEbDkubg6LEqI5V85Qf2qfOrfY91KsBhV+RIdJjX0BpzVLRb1M6b1yWPAjEJoynIhkWMnJw5oxVK0Z8vKegpJfLO0TxjjYiTD/PLeclXOXNkjsRw+Flxlf1Zkfk8zGIJIU8TFfVUYK6APBf98on/aAOdb/cAgdaKWqTxBUEJh8shIUJHsytGP1JIQAvQcY/Azju+0c8EEDIgJkKJrKuR164zdd6tXvYe8Xa1PvTfluiZBVltXilOVvAfwTpd8Lu0= X-MS-TrafficTypeDiagnostic: AM7EUR06HT236: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zQZA+b79R175bkA1zIGFbnqQ57nA5M8mdIuBerlaelOWpG9p+5cSjDvam1gvZbiE/FCEGPqln0ggpfSmEktGcvRJLk3WFOImqsoVOz94D8+GJllDacw6cMyCUehdgRJz3324hZso+uKZs0NwOVGZJ1zJHeLkLx69ZDbDAtTK94QnBKqCOzDKXdmzriigqkjxbSbOSSIK+GWQlS3tEO27ZiQ8kwQTxDkmcQGtmyvfkpMzCF06r47IuTzVHOTtGDRaObNmkBA8K/gh3egAU5S9v7o/Kou5jgXlnAN6nqUpkqqwt4F2CJfmqxH2fzui6os96AupePcfJdTX4qJSlaF4D0E6h5a8YRLbTjL8/Au46ZFM2+d2HRw7N+NNb+Rx1HCRJZkr4vOyIFAfSn+kyNiOAg== X-MS-Exchange-AntiSpam-MessageData: jAFVLUPoq2SBeAIi6O39ne6MWNEDEIadtca7GRyYtgtFHkCPffDS7deVcGk3qydrvD1qblNwdEMHfeRFqtrbFRbIvy+D/Mj/o6IYEBhlSFcZDAbApkNFzWQ3a/KptZ7tFy6TSyR6sr1/Q50Pedi77g== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0cca47d6-8cdb-4830-0995-08d8f7d47472 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 01:45:13.3652 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT063.eop-eur06.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: AM7EUR06HT236 Subject: [FFmpeg-devel] [PATCH 4/6] avcodec/rv10: Don't presume context to be initialized 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" In case of resolution changes rv20_decode_picture_header() closes and reopens its MpegEncContext; it checks the latter for errors, yet when an error happens, it might happen that no new attempt at reinitialization is performed when decoding the next frame; this leads to crashes lateron. This commit changes this by making sure that initialization will always be attempted if the context is currently not initialized. Signed-off-by: Andreas Rheinhardt --- libavcodec/rv10.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index 89b838ad15..bd70689cab 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -226,7 +226,7 @@ static int rv20_decode_picture_header(RVDecContext *rv) new_w = rv->orig_width; new_h = rv->orig_height; } - if (new_w != s->width || new_h != s->height) { + if (new_w != s->width || new_h != s->height || !s->context_initialized) { AVRational old_aspect = s->avctx->sample_aspect_ratio; av_log(s->avctx, AV_LOG_DEBUG, "attempting to change resolution to %dx%d\n", new_w, new_h); From patchwork Mon Apr 5 01:44:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26744 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 B5D7344982B for ; Mon, 5 Apr 2021 04:45:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9FACD6880A8; Mon, 5 Apr 2021 04:45:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR06-VI1-obe.outbound.protection.outlook.com (mail-vi1eur06olkn2092.outbound.protection.outlook.com [40.92.17.92]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AB697680946 for ; Mon, 5 Apr 2021 04:45:35 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DLHkGhDsvSV5g3rXsduo1V4UendyHHwf5gKEvCJbtWDsSb2XXBrm1tD7Y4tVSCUpvIIOYhqGVAq+bEPBo4B7wrMWsgwC8OfwsveFFcsCrPRVNekCALamzGzX2WKafC3o2YRu1xn63/vBQPwj9H+xOZQQ/Hriul/6gYSDmAfv2YhKjtnuvYZofBeICIqIcUmob8p7zLCeHcI5I9FTJXlj+MuefDkuoZ4ZCJ63PWxKObPMAtw826wwYtqEjLWcEfFJb+sc88lOTt7Vvqe3jJdXrYtBxD34QYGyn0bOL1oun8DYN7olmju7i29G1Th1mFOpRCAD+Ofd58FrVYr1x0qw5w== 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=CaFoSkCMzI+fLhneTk0lqGBQL7DpoeyO/XTkdiGZQc8=; b=fG2bzNd9z+vsOXJLVjGFd6sLQRZtFDxPOFqinbIzMlqPGH7m9eJ4ljr+AYrk3KMsmn8K/Uk++pFSkRHzAZrI58jBzIID70HqVUhplAkTJTruSzmpOTnAQSnGKC4GFpq6ZByIx/5GDjusppzwK32Xb+nrKk2fWKiWdWHcBvXCinm+4jL9pchVb1ufR+eN1w3exLsHAXrJ6DrhiVE5EWg8IWcp1Ga4Ef65aqzoYh+/5LUYg95kq5YxsrAx7UM9FS5tuzerFzfF6RtK04cd0xCmgAiuVTo9yJCMjZrs47dCYc5vUDueCzwyARNce2GL+VMUrxZMZUf/fPmLBfcnnAkPfw== 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=CaFoSkCMzI+fLhneTk0lqGBQL7DpoeyO/XTkdiGZQc8=; b=rQBLqV5P+G4I6A/a8CExgs0K1GINSZTJMaahVzBNS+3C+v854Ptzsf6sLe1EfbfJ2yy38Tt2OQdb5p3QoKuAEC9oMCyTOJdxTCm6Y86VYcwCUE2skf2TjJv8FNHkj/K16qX60SKQ6ZDBZn15XQ3Mze7oZyIj0JTX1QFDrDmKQC080j7r+rmgxl/1rWfc67rZtnJlsqI/XhSdorNuPIalfKM/gaxGoDQj8CnSfAU2LflUSzzfx6qoD7PRbo9fXec4F2bYZfR1yE+j5XjugXRRvdmkl93AIuTvy2JXvdSWmvI6FxLDckJPzt3pWT8dJ9sVZy2Erd6OKZKu2bacwpG+AA== Received: from AM7EUR06FT063.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::51) by AM7EUR06HT210.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::476) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Mon, 5 Apr 2021 01:45:35 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:fc36::52) by AM7EUR06FT063.mail.protection.outlook.com (2a01:111:e400:fc36::403) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 01:45:35 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:E00E218BDE35C2FDA11FFB5C32E9F3A0FE5D7CFA5DFF5B19788F58A043305578; UpperCasedChecksum:37EFA4220534A571948BDBD6A87062066ADED31EA0CDA4B16CCCDF5E8BCB261C; SizeAsReceived:7608; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 01:45:35 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Apr 2021 03:44:33 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [lMeVIt+JNzR2RdC1D2Mw+Lm3W8VptA45] X-ClientProxiedBy: AM0PR10CA0039.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::19) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210405014434.3973535-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM0PR10CA0039.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26 via Frontend Transport; Mon, 5 Apr 2021 01:45:34 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 1423a9a4-eb98-4a44-9cde-08d8f7d48152 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNUT6BysHa+24QDXCmt+/ofHIH4lvje3dxUDOsJiYL6lQV5xq+3rkg9xHa19Y6Gm57k78aO8s7uZHF4w9w9OTNcb4X0ZaBqOBe6/ud0WGTcJ4r2Lifry9CEfXwuQcBE2PgnpYUHvJcQYA8UezufVdsS1WeUksjVtcnAOKFRFTKnL0tn1NE4cA5ti3as7RT8HXroiI2/fdHK44t5vHzIHCs6zOZinvNzsrxopqh2tm1YSv++tNYgg+Oe01+Bg/ToZ+sdh42QH8lPxX/ayCD5xPjLP2OqzSdk+UMeA8v5SS3GSYlKOde0UHx5N6o7AWJIXupJj71Ol6xrG9QIiYIIs7+shwZT9i/qoj0l6gonmCyXZjafxwigWav2DjuJ0CQnCyvBt410ooLR718/k7yYBjcYWq4GAAqUVvMkdHXnLzolxV6APINoH6qHw9/o1gyjn51q+O8xoah9D+HRfq8z+NVQOgjEV2y1KCYK2bPnlJFufwbZP8yHgDrsJrJgSDZdEglRzcWYZwnsYYMQ8nSCeH5pmbAfhI22OSzydw2EVx3+Mdoyara4yW59w9vX4szx7TaRdXEn3ySd40CAivP0oj8Gh/dYNcPVvyWUrIrRDopWLvksEMq0U/xgZuKk7PvJmp0ic5sDgXJ3p+1SAepMOgCqEvIdfbC+ArQnS7zUknOOxkmRxH5+2qgHBMxsB6EsQ/dMeEOec1lMuq7j3ZgpgM/zsFC6txCDULBI= X-MS-TrafficTypeDiagnostic: AM7EUR06HT210: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IyDOqCN1fopSk+WPxg8Lh0LyzSGriGnSFCgMmH67h5ZjOH903r5nJHnUCyLu+A4M8ZpeRVKEfdM8ooF/zvtB9uCFTENEEifxfaYrj9Rx7Qg2tcF/V00Rvg2pOOQadi3IpWOtiTUIDRUEP6ZeUwxhAWa40OmFcDX+o19+alG4NfK9kFvz8O4TQ3c6tEm2OlKXHS6wlAW9IO+vblvsC+xd5WPJYKraUtTcJDAf7/abCVYIIFEuRojSK25n6Z9FXKhVcxQcgzYlYI/X+4Eh+nl5bgEUc/bGffVCKKC0KYvCu8x8C3w1cJTJAYg+A/Qac/sHeXcumMBIK0Z3Ebd0HBjNc6zgpFCqoD0VpC0jeQsHB9eUxA5Pb8nuTOYSGMQcIisnb8+avIVyvz8dqya9JPYAbA== X-MS-Exchange-AntiSpam-MessageData: hGO9GM613gNhpT8T70E72xAJ9P2wm4HcT2ib+lYAIdsSPCf0v9HjFMR74/jOJPzGxXsPqVJGWuPOaLQMaT2v6o9DZiA7Nvh2KA4fQehu7NxxnZVaTRW1sRLDcXzT14Se6BHC16Xg0sb91nt96IIgdA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1423a9a4-eb98-4a44-9cde-08d8f7d48152 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 01:45:34.9386 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT063.eop-eur06.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: AM7EUR06HT210 Subject: [FFmpeg-devel] [PATCH 5/6] avcodec/rv34, mpegvideo: Fix segfault upon frame size change 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" The RealVideo 3.0 and 4.0 decoders call ff_mpv_common_init() only during their init function and not during decode_frame(); when the size of the frame changes, they call ff_mpv_common_frame_size_change(). Yet upon error, said function calls ff_mpv_common_end() which frees the whole MpegEncContext and not only those parts that ff_mpv_common_frame_size_change() reinits. As a result, the context will never be usable again; worse, because decode_frame() contains no check for whether the context is initialized or not, it is presumed that it is initialized, leading to segfaults. Basically the same happens if rv34_decoder_realloc() fails. This commit fixes this by only resetting the parts that ff_mpv_common_frame_size_change() changes upon error and by actually checking whether the context is in need of reinitialization in ff_rv34_decode_frame(). Signed-off-by: Andreas Rheinhardt --- I actually don't like that we have two flags that indicate whether a MpegEncContext is usable or not; how about we always call ff_mpv_common_init() during init (and never lateron) and make it unconditionally allocate the stuff that does not depend upon resolution etc. and add a parameter to said function to also allocate the latter. The decode_frame functions would then be modified to always use ff_mpv_common_frame_size_change(). ff_rv34_decode_update_thread_context() currently checks twice whether the source MpegEncContext is initialized; the second is trivially true, because of the first check. But the first is also always true now, because ff_mpv_common_end() is only called when closing the decoder (and said check also made no sense before this patch because a noninitialized MpegEncContext would have led to a segfault pretty soon). Should this be changed to check for context_reinit instead? libavcodec/mpegvideo.c | 6 ++++-- libavcodec/rv34.c | 13 +++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 7eddbdcc37..5de0719f83 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -555,7 +555,6 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, } if (s->height != s1->height || s->width != s1->width || s->context_reinit) { - s->context_reinit = 0; s->height = s1->height; s->width = s1->width; if ((ret = ff_mpv_common_frame_size_change(s)) < 0) @@ -1099,10 +1098,12 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) if (err < 0) goto fail; } + s->context_reinit = 0; return 0; fail: - ff_mpv_common_end(s); + free_context_frame(s); + s->context_reinit = 1; return err; } @@ -1149,6 +1150,7 @@ void ff_mpv_common_end(MpegEncContext *s) av_frame_free(&s->new_picture.f); s->context_initialized = 0; + s->context_reinit = 0; s->last_picture_ptr = s->next_picture_ptr = s->current_picture_ptr = NULL; diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index 7e5bfe0e22..99e580a09a 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -1383,6 +1383,7 @@ static int rv34_decoder_alloc(RV34DecContext *r) if (!(r->cbp_chroma && r->cbp_luma && r->deblock_coefs && r->intra_types_hist && r->mb_type)) { + r->s.context_reinit = 1; rv34_decoder_free(r); return AVERROR(ENOMEM); } @@ -1530,7 +1531,7 @@ int ff_rv34_decode_update_thread_context(AVCodecContext *dst, const AVCodecConte if (dst == src || !s1->context_initialized) return 0; - if (s->height != s1->height || s->width != s1->width) { + if (s->height != s1->height || s->width != s1->width || s->context_reinit) { s->height = s1->height; s->width = s1->width; if ((err = ff_mpv_common_frame_size_change(s)) < 0) @@ -1667,11 +1668,12 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, if (s->mb_num_left > 0 && s->current_picture_ptr) { av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n", s->mb_num_left); - ff_er_frame_end(&s->er); + if (!s->context_reinit) + ff_er_frame_end(&s->er); ff_mpv_frame_end(s); } - if (s->width != si.width || s->height != si.height) { + if (s->width != si.width || s->height != si.height || s->context_reinit) { int err; av_log(s->avctx, AV_LOG_WARNING, "Changing dimensions to %dx%d\n", @@ -1689,7 +1691,6 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, err = ff_set_dimensions(s->avctx, s->width, s->height); if (err < 0) return err; - if ((err = ff_mpv_common_frame_size_change(s)) < 0) return err; if ((err = rv34_decoder_realloc(r)) < 0) @@ -1744,6 +1745,10 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, } s->mb_x = s->mb_y = 0; ff_thread_finish_setup(s->avctx); + } else if (s->context_reinit) { + av_log(s->avctx, AV_LOG_ERROR, "Decoder needs full frames to " + "reinitialize (start MB is %d).\n", si.start); + return AVERROR_INVALIDDATA; } else if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) { av_log(s->avctx, AV_LOG_ERROR, "Decoder needs full frames in frame " From patchwork Mon Apr 5 01:44:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26745 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 B427744982B for ; Mon, 5 Apr 2021 04:45:43 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 98C406880C3; Mon, 5 Apr 2021 04:45:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR06-VI1-obe.outbound.protection.outlook.com (mail-vi1eur06olkn2090.outbound.protection.outlook.com [40.92.17.90]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 426B3680946 for ; Mon, 5 Apr 2021 04:45:36 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YnyDaYGL5yvS651cb2aARaRXZtBXOKAi5DOWjkdxuqBuQ+77hzkVswPMD1XEpl3pB2PSgRHdltNjPS2GF08vKNAjtxb2yVQT+48g2XugzdrxrOwQt5X0bd9wkNRY3Wt9k2hgWsayTe5oRUAZqjLxhPBje4pxhTKxD+Q8E+f9dbDXDNyBl5l7DFcWB26JqJ30P+b8rHL/VXLcq/b4d5dimQD9MchCuVWz9g9SL5XWKUSXFMuC0RpvQZYVnIa6JJPtBrC1ucEr5OpgMwICevUJUvFgW7vQRaXL6q7YbWHA+dY6ac8k9Doi/pomGRde2JHiFbDLiwiQ0FGiQt6s805Ljg== 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=+RzxgQMAnOcAhYeFYnbqhiWLOo7yiu3lTkI4Xd8K8A8=; b=ch0dZRTEA1pAy3/SrsTbijRxtu3t9ydvhg7qJ5H7VKssotmJRVlkVPFxsngphE8tI6wXiYRyAQ5nvjI1jCop4RhCLLlwazDa3LPZilLOY5YrXIRGQbGL1iwEiHeZFEW9IXKvBC1VMoidc6U2heTrYf41sV1sOHcFgdsiTc3MCrY+y40lUYZJK1sEzIuk3Bnbv5opm7HmEwHyVShYh7AeANAMEpI/zjibHpv3zvxCnqfqJ6ISwzMQHqhV2PsZT+0/s2Yzi+j8yUPw4+VfGcqiE922PxIfX/iPEEzt9wO46mMJnzwRF4fQR+Kjkbly2JiFChxDLNJ+Sm6V3y1GRXi3Ew== 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=+RzxgQMAnOcAhYeFYnbqhiWLOo7yiu3lTkI4Xd8K8A8=; b=bJTT6KUiLz8RDghy9xi1H+lDcft0m46/rUEdpHpJIiK5DRQjlSOuLh4EFndbjw/Mr1AIiWSaRdIdSAnb+K4hE+ADxlo65HBuPqIZ3jjZZ8k01pPzlEDny+6dXsG0nUWz9DVqaensOqygrvpw5A8q3HSaiimBkMhX77Mw82OFrAKwo0TCscHDJPJllzfHeY3tuOUOCNkLKWefEbx+HXtc1d5ZapSaUT/R4kq59sUjrEXMHZPI3qmtpXxSck9Jbb8YJUsjxOiBYad45qNQTLdcYywelor3vshQXUa4s9LrRub0xn5TS1X1n7Z6CMm+L9bZbs8nlsgj2HKK8cfxp1u0Sw== Received: from AM7EUR06FT063.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::50) by AM7EUR06HT032.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Mon, 5 Apr 2021 01:45:35 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:fc36::52) by AM7EUR06FT063.mail.protection.outlook.com (2a01:111:e400:fc36::403) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28 via Frontend Transport; Mon, 5 Apr 2021 01:45:35 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:2C172DC8EF94BC8D92534D8F23303EC6A4A560EBECBF05C041B68FFCAC10266C; UpperCasedChecksum:8F25A4F62A75026A9D1E3D2D74A2AEBBE6D942170F50AA2332267070F822AD44; SizeAsReceived:7595; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::8128:5de5:4e94:9a21%3]) with mapi id 15.20.3999.032; Mon, 5 Apr 2021 01:45:35 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Apr 2021 03:44:34 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [bHOOQwwfNyufWWLre5lEhbRHG7ci7AC4] X-ClientProxiedBy: AM0PR10CA0039.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::19) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210405014434.3973535-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.96) by AM0PR10CA0039.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.26 via Frontend Transport; Mon, 5 Apr 2021 01:45:35 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: eec0f81f-5b3a-43b1-a71c-08d8f7d4819d X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiS3KLhuc01YFDN7B235wyuedQvkoheZYP7NcrtLAJGMWXdSzygTbeZVQeuY6JE3PioIeYYBwjtkhF9ouNdS/Sp8W3d8Mtmn+YVnV4oODIrfFKvv/q7st3I9W2ZwpDtUj0jA098iWtyhCzup8rEqbYOM/74yFiPOfdlcMg30X+6RuxpVejK+rB1fEAsVCH2/vPRiy9h7YYYeuZY2VaZFUJv+wq76SyL6XHXuuK3yOYRGJYe+8vSQZoWfCP0qJpX9T9vVx9j3hjBeQ/y4Bk1GrwEDC6CD4oeaupMte7KqymQ577RF2o45Q+QHpyQZWNHGjBE0bOTRrnDEWkezXmr44v923SOF4coa7iLjDfK7fg8OS1IUSYa/hyFopcpvDLEUaqdV22jC98/H+cXAiVeOHmgBCAa0WcSQKQh7cKpvhSwu16uBOfxqJI3+5nt7NxJkDysVXq2fCl0L6q2VDiMgHmCbGKdW4IMHqQrio2B9YgAhEqtoV2+/POabqf1PNS4K+AMb1gDbqxdrmywvBFqrJ56afy6+7nm3HyTdxR7XcEQ3TXwoIBAxO3fcm6FV6Ng4zwmI9szdaMbMDrW46usmn9w3/MfKrFJGwjMa5W6JQ4fsUXkpec8q8kmU/H8n/LBqcaDJEpsw96ydr9XfFozqM53Zo0GY9YWC/ddtAXjTsc8yKcXoLSmR3fthELzC1vbapiKzQSYBSw3ElF/IADyf/BF0biBC7neiqvYp3i5aSXRPioiq+aivdLeSzBlzXA2UvNg= X-MS-TrafficTypeDiagnostic: AM7EUR06HT032: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hl/VPhgUjnBfmL+UKLKxd8/0DZx65y8lflg/RitDU5HfwUviP/Uz0qK2crTLY3wyR2R1EWxEvaSBCb0ATzuvf4CVFm2DHNlvfDsos9c+OHIK00/AggZmLiVyhZo+PrZ8bZk8/DvGfK0WY+D8GrCOsbpq0ggncr9clpyROw4DmjG5KLQAWUnJ5aPP2bW5x3ji+87tacLn0K3/sgBiaJciSYv++YlF4Cb0rCvUIL/NEwvXYtsbYNwbOLHhJm3dOy3THybzS1jZqC6RQsHT+EaUj5OjbChiYiuAPaKFy0feXweKVz4mzWLLNSMICogCzvugPAbvDEkdfMUWUeMkvntz95RGPyK+uhm3oTxXBlP/Mtcmwr80r+E+boPbh+PkgQw5lnDBGXOh1patzVmuLrlzKg== X-MS-Exchange-AntiSpam-MessageData: MHA4ZFeRrijs2bFLDnyH1lMEoalItHBlMkQkHgHT0YcWkTOgmGxlx3mClS4gAwi99mngHr4QEEAb8Y+toxXcsqvt+Wyyi4YVcglT7ApnUurSIIIBr9faDOcxYlZ/RoXNcg4/fORLiQB/8tpdXF5+6g== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: eec0f81f-5b3a-43b1-a71c-08d8f7d4819d X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Apr 2021 01:45:35.4754 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT063.eop-eur06.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: AM7EUR06HT032 Subject: [FFmpeg-devel] [PATCH 6/6] avcodec/h261dec: Initialize IDCT context during init 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" Before 998c9f15d1ca8c7489775ebcca51623b915988f1, initializing an MpegEncContext's IDCT parts occured in ff_mpv_common_init() and this has been called in h261_decode_frame(), not h261_decode_init(). Yet said commit factored this out of ff_mpv_common_init() and therefore there is no reason any more not to set this during init as this commit does. Signed-off-by: Andreas Rheinhardt --- libavcodec/h261dec.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c index eb544e6046..0d8cd8c20d 100644 --- a/libavcodec/h261dec.c +++ b/libavcodec/h261dec.c @@ -79,6 +79,7 @@ static av_cold int h261_decode_init(AVCodecContext *avctx) avctx->pix_fmt = AV_PIX_FMT_YUV420P; h->gob_start_code_skipped = 0; + ff_mpv_idct_init(s); ff_thread_once(&init_static_once, h261_decode_init_static); @@ -595,10 +596,6 @@ static int h261_decode_frame(AVCodecContext *avctx, void *data, retry: init_get_bits(&s->gb, buf, buf_size * 8); - if (!s->context_initialized) - // we need the IDCT permutation for reading a custom matrix - ff_mpv_idct_init(s); - ret = h261_decode_picture_header(h); /* skip if the header was thrashed */