From patchwork Sat Apr 24 11:14:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 27276 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:49c5:0:0:0:0:0 with SMTP id w188csp2034869yba; Sat, 24 Apr 2021 04:16:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlNccD5n41s86uS81Q04NcveN7F+3JpuTFrvMWBL2IAvTNtB/YJvqHmyLp7av89xsznA3x X-Received: by 2002:a05:6402:1cb9:: with SMTP id cz25mr9705809edb.163.1619262967202; Sat, 24 Apr 2021 04:16:07 -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 dm17si7465216edb.190.2021.04.24.04.16.06; Sat, 24 Apr 2021 04:16:07 -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=JXJpnL7Z; 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 B42A468A046; Sat, 24 Apr 2021 14:15:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073083.outbound.protection.outlook.com [40.92.73.83]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CD105689F4D for ; Sat, 24 Apr 2021 14:15:37 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ln2U9zE+3k0WcA3ZeufUaUoA0U7jIB4qrNh0kqk/ftHi90vhs1hu5Rsn7yhtOZ0EpyEjF+FvgB+qJqeH6K9g2jfXmFj+VciQA/9oiKX1Eem4OTHoytZ7O9MuTLGWhg94CgZRmSsL+9VAs0Y7NhVslsM01eRZEN4MPspyRhbWnL0i2osIkR77OC8LkW4WQ4CyuFPIYZSbFRlcunRzJBVf9Ruf+6e7cQVAszZ8oSRDggOwTDRBUE0etrt523E3Fod/nGulmgDbInDBUCfH47xepHRGUYNrs2z/uNajRnSEvR/zyQ4X4ORL5kjWIRgC9Eq7GWXhIMei4gMeX5ovazOlEA== 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=Rs9aZML7G4/pLUiPHzskK75NezF+QkLqY4ZWIAO6TB8=; b=SudP8EaDjzcEflGy8k4sOjOaRIkv5QA2B1ASa2zkFeADSkO/vmHPuk1itNuz9YQ6kXXtmohuudi53KHADOAItwoYxk5usVj5eb8a5zjQpj+D/MnH6UJX7iKuaST7h8iaw9AxBBdYK69Xx+MgMUnGMr/AoejwgRNd4VE+aF92pQlCTtwUk9uLQkPYUYSFfUiVaFMisygtle4dfQ+/s/xDzkw+0iv+ffoZjkn/DkLj4eOgfc2ekQyjcR0zYmx3paL4LRcY0g5XMxA990UUZz5jvKSh/1IIzOx5SDoNk3L0CG8IXJojFq7mIZZWzbKWtoWbIFob/qJFM2BFMkzctDBAPg== 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=Rs9aZML7G4/pLUiPHzskK75NezF+QkLqY4ZWIAO6TB8=; b=JXJpnL7ZLtKz1inO8P0fICPx6bc2ucod173rl+8d1XKT+VfomJ+m8dEa8DE1QO4U3JiuA0jkoUDYPq0nJhK30hYsMWh1HoPpHUm2lxqGxtoi2Q7tyNZ6CoutSSO+Xv2L8Or5KvCLUnp2qPKH/hUOHrsh9hlmcKn5oTQLfLLsKpW2TnAqOM22zgNsrRiWisVkEMqKUdaVaWBaiTKu447VT25vonv+haTQdfsZQ2umU2d9s5W+cTBOkGcAdBvVtRloolY2vC32DLi8wedntHtY9S5NnbTuVctrFvl+77wR8rCBzZDBwcWKhOGth4eqBBuGY0ihKYwGmkPhGR9IIMwEJw== Received: from HE1EUR04FT042.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0d::51) by HE1EUR04HT122.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0d::362) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Sat, 24 Apr 2021 11:15:36 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e0d::46) by HE1EUR04FT042.mail.protection.outlook.com (2a01:111:e400:7e0d::159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21 via Frontend Transport; Sat, 24 Apr 2021 11:15:36 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:89460F8A6C394DD9245DAA2B2765BF08CDB3BD3D5E99A89B5BACB9F348A01B97; UpperCasedChecksum:D0C4F0783CE81E3FB86D99CAEFA985752372C4ECEC23B55746448E260FEA2546; SizeAsReceived:7593; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7%5]) with mapi id 15.20.4065.025; Sat, 24 Apr 2021 11:15:36 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Apr 2021 13:14:43 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [o1cEK/r6lGCLQdcxXhifcqFbbwcmWJ7V] X-ClientProxiedBy: ZR0P278CA0160.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:41::18) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210424111446.30338-10-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.193.248.86) by ZR0P278CA0160.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:41::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21 via Frontend Transport; Sat, 24 Apr 2021 11:15:35 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: a428fe4c-b3d8-474e-5338-08d9071248b7 X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UL2UDcFXhKBVDdW3S05RF0ZpKXZzuzZ2TeLJYmequqXBGF7rcOvburfh+SmjhYZzLqpw0yHVg5ISB6faUfGK94sWvIUWV8oF+K+Z1SprxgQtgKTfeVln9YydqLv2FrSCs6N/8UOpYsAOyGayczxG2OR/fEeepXAKMqJ7ffxoNuPYeCG3CAclRfz4V5Rw3YHLcnS9nu/haNShmnLel+pWCuTrOWtMolJj+G86VdVqplA+NU5JlFEa4x+2OrktySUlzFnkIbdRJ3/2n6Uk72oTDs04arw4RbaEqDp/U+Wp3YPXOxZHOt8g/sQTd9pXcoI6vxuSlknDdO5ezvi/ADSt4K4n2xLvFzc4/ntS2G5VFElfhidnUG59UqZE66zzIf9sm3qMMi2CyzB3ZrgWFmHpnYae1lAAaB9B2KMEHXkqZCBtDCEWCqfikexwiHKpPgDeK0OgTginKO4W5yPDKBwmr2QW2ry0x/XBys/5K9XluhzULS/XIxH4ggevq/dRS2Z+jycgQk7/PgqB1nKcZUZGg0ejAtAJpTsyAPX9S4/SRxtf0M2esMYgSv+WbMgG4C34UvjVMlVTugbueKt7Wab7+6rJpdhVYH17Ddu9uKfyo0kLGRsSw1B0OM5vV1WeGD+/AE16C1BXMMrcee2BCkA4Tm+LbjbMIYPkVYcc3/LneN/h6K2iKZgEjSaPK9s7LZopImpCJPEAD5Rfg== X-MS-TrafficTypeDiagnostic: HE1EUR04HT122: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +CNGjDXabgeH+an3GX1VnROKvuVtB1cCE/Hy0yMfMnvJyfKlLIVdWogi/4ryJGjE1xLpnk/jcsOsyigWTpGtnvYaLHzttgUQbUp3gp3MgaCS89QANSlPdu1oZjqWT2LborHelhHRgshkTQ1UwryYwDrX8Rzth1f37SKTEVjlr0zlrX29dKqd1MMiHCL/jQGGciOLDLkfOx2mVfvi0BSpsKwZpFmeki+9fQ/5x2YidfrMiLSSCHKJgryiwd7jh1it9LcXesnonRvv048WDCsWIueMQZWW7XXUcNoWkOT4q4fj4LCTBjKHNA0Tyafu7rqD6JpRzb9JiVq4PphjHEMRKU+BBgZjj3XUWNeU0o0w69ydO01kq1FI/9752B/CKo3YLSOvQxXxDMAvVe7m7Jo3UQ== X-MS-Exchange-AntiSpam-MessageData: 3lixqxnTwPBQmUDwx7nqh3Ld+dJSPOqY8TFADknTR21uSNMndS67qGtH7rB0CL1XrNChoJWuZ6vsgA3eD49k1xCKH5ooWmW8RNpIOMucSLxcvtINzrdac5Olua8t9F3rtM+8g8+GP2zEULRFn/t0Ow== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a428fe4c-b3d8-474e-5338-08d9071248b7 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2021 11:15:36.2184 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: HE1EUR04FT042.eop-eur04.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: HE1EUR04HT122 Subject: [FFmpeg-devel] [PATCH 11/14] avcodec/ffv1dec: Fix race when updating slice_damaged 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: pEASVd2zYNQy Content-Length: 2441 A slice is marked as damaged when its checksums indicate an error or if it is not a keyframe and the same slice of the preceding frame was damaged. These checksums are only evaluated after ff_thread_finish_setup() has been called and therefore setting them actually constitutes a data race when using frame threading, because the decoder's update_thread_context copies it. This is undefined behaviour, but in practice it works: If the src slice is damaged, but its preceding slice is not, then it is indeed uncertain whether the dst slice will already be marked as damaged in update_thread_context(); but decoding the slice only begins after the src slice has been completely decoded in which case the dst slice will be marked as damaged if the src slice is so marked. Yet it is still a data race; fixing it is easy: Don't copy slice_damaged in update_thread_context; instead just reset it there and only set it when it is known whether the src slice is damaged or not, i.e. after the src slice has been decoded. This fixes all ffv1-FATE-tests with TSAN when frame-threading is used. Signed-off-by: Andreas Rheinhardt --- libavcodec/ffv1dec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index c9583db60a..c16fc81927 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -1060,7 +1060,12 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) FFV1Context *fssrc = fsrc->slice_context[i]; FFV1Context *fsdst = fdst->slice_context[i]; copy_fields(fsdst, fsrc); - fsdst->slice_damaged = fssrc->slice_damaged; + /* Reset fsdst->slice_damaged here. decode_frame() will set it + * if the slice crc indicates an error and decode_slice() will + * set it after the same slice from the previous frame has + * been decoded if said slice has it set. Copying the field + * here would be a race. */ + fsdst->slice_damaged = 0; if (fsrc->version < 3) { fsdst->slice_x = fssrc->slice_x; fsdst->slice_y = fssrc->slice_y;