From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id E97D847DBE for ; Sun, 25 Feb 2024 10:01:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9309768C6A7; Sun, 25 Feb 2024 12:01:14 +0200 (EET) Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 943A268C15D for ; Sun, 25 Feb 2024 12:01:07 +0200 (EET) Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2d22fa5c822so31034051fa.2 for ; Sun, 25 Feb 2024 02:01:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20230601.gappssmtp.com; s=20230601; t=1708855267; x=1709460067; darn=ffmpeg.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=AQpufePCOVBKKwb9+86VOgucNSmrUwCJ+sZ0INGd5ag=; b=ngR4uqACXmc19+DLJ0+30/DzG9rc/Bkkke8FgVIKTOFiq7aOHqOVi9w5n+AwLiwPGe 7eyAZvkfwTPf6GGUG1uvfxpQtVwzJ//2cpdOB4/mlQtYrf8998EKlHgPUVa+0wHlQTvG 7iqChMCcFLeiwNP41opBfLDBA/X1Hk6SDVv0c7aae5FI6DtxkDr3RrHRIQB6t8mPa+l6 0uHHxDnXqwZ+PpepmUmuEwIgFh7aUKdhgcoGjWp8yS3ijieukFo6UHD2zQEmdyWbfxwy SWIwIGUyGaWaWAbXwLjK2LeX49ZpMrT8MdJWHoxswfnwS0zbLcVXlNbymIfUfxOE5cmN V+9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708855267; x=1709460067; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AQpufePCOVBKKwb9+86VOgucNSmrUwCJ+sZ0INGd5ag=; b=KEr1nGoPY6NtSagTI1S93o/eV7mUdTns9DE98v3+9Cp6YW9dp6k3vexdmIRxD8cCyQ 2lSYHV8jMEItCuRG/MJYwa8Xw01EqSe/xP6WUMvV4rAuv+ateeRFRl7CsINkHtZ04VFQ wWhsZvvYVPXRX9I6clOK38eqTTValSoRPy+idynf0BylOh9dc8c/rCHhRn0D3UWAwxSH AVkwaam3rqAFwS8fQz9Wy5V2TKtfZab5V0BXCPYLslcPK9ugbZRi3/kcIbbElW/m2tB7 4ii90Tv+PXHe+7w679eSPiAwqJ5rP5HK4Oly/ldG0KfYs1e9KGq0gza6WQbmAQwwzNY/ 7S1w== X-Gm-Message-State: AOJu0YyNfSt47NC13hSX11gAOkD8+aKSH1B+hfYcQNne9EE/zmKh0eBL Iv6ehYAzssRQu2obUeHKcA3NOI48IPZ2XT+fpO0pY4QBCdqoeI6qT4WvoLc69gO89xP0kBLMehx k X-Google-Smtp-Source: AGHT+IFlRJuYrPtsNpt8cOX7p01vlLcl/ERrjKjm1n7dmdfA8D48SU5dxmg0hiK7LXvlzgmy0vQ47A== X-Received: by 2002:a05:651c:546:b0:2d2:5057:bbf4 with SMTP id q6-20020a05651c054600b002d25057bbf4mr3142417ljp.20.1708855266640; Sun, 25 Feb 2024 02:01:06 -0800 (PST) Received: from [192.168.0.15] (cpc92302-cmbg19-2-0-cust1183.5-4.cable.virginm.net. [82.1.212.160]) by smtp.gmail.com with ESMTPSA id co2-20020a0560000a0200b0033d70dd0e04sm4784073wrb.8.2024.02.25.02.01.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 25 Feb 2024 02:01:06 -0800 (PST) Message-ID: <4650b565-9b2a-4023-9c45-9e00086e15e0@jkqxz.net> Date: Sun, 25 Feb 2024 10:01:34 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: From: Mark Thompson In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH] avcodec/cbs_h2645: Avoid function pointer casts, fix UB 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 25/02/2024 01:55, Andreas Rheinhardt wrote: > The SEI message read/write functions are called > via function pointers where the SEI message-specific > context is passed as void*. But the actual function > definitions use a pointer to their proper context > in place of void*, making the calls undefined behaviour. > Clang UBSan 17 warns about this. > > This commit fixes this by adding wrapper functions > (created via macros) that have the right type that > call the actual functions. This reduced the number of failing > FATE tests with UBSan from 164 to 85 here. > > Signed-off-by: Andreas Rheinhardt > --- > libavcodec/cbs_h2645.c | 15 +++++++ > libavcodec/cbs_h264_syntax_template.c | 35 ++++++++-------- > libavcodec/cbs_h265_syntax_template.c | 58 +++++++++++++-------------- > libavcodec/cbs_h266_syntax_template.c | 8 ++-- > libavcodec/cbs_sei.h | 7 ---- > libavcodec/cbs_sei_syntax_template.c | 47 +++++++++++----------- > 6 files changed, 88 insertions(+), 82 deletions(-) > > diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c > index 2fb249bcd3..8e4af7b2cc 100644 > --- a/libavcodec/cbs_h2645.c > +++ b/libavcodec/cbs_h2645.c > @@ -235,6 +235,16 @@ static int cbs_h265_payload_extension_present(GetBitContext *gbc, uint32_t paylo > #define FUNC_H266(name) FUNC_NAME1(READWRITE, h266, name) > #define FUNC_SEI(name) FUNC_NAME1(READWRITE, sei, name) > > +#define SEI_FUNC(name, args) \ > +static int FUNC(name) args; \ > +static int FUNC(name ## _internal)(CodedBitstreamContext *ctx, \ > + RWContext *rw, void *cur, \ > + SEIMessageState *state) \ > +{ \ > + return FUNC(name)(ctx, rw, cur, state); \ > +} \ > +static int FUNC(name) args > + > #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL) > > #define u(width, name, range_min, range_max) \ > @@ -2070,6 +2080,11 @@ const CodedBitstreamType ff_cbs_type_h266 = { > .close = &cbs_h266_close, > }; > > +// Macro for the read/write pair. > +#define SEI_MESSAGE_RW(codec, name) \ > + .read = cbs_ ## codec ## _read_ ## name ## _internal, \ > + .write = cbs_ ## codec ## _write_ ## name ## _internal > + > static const SEIMessageTypeDescriptor cbs_sei_common_types[] = { > { > SEI_TYPE_FILLER_PAYLOAD, LGTM, thank you. - Mark _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".