From: Mark Thompson <sw@jkqxz.net>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] avcodec/cbs_h2645: Avoid function pointer casts, fix UB
Date: Sun, 25 Feb 2024 10:01:34 +0000
Message-ID: <4650b565-9b2a-4023-9c45-9e00086e15e0@jkqxz.net> (raw)
In-Reply-To: <AS8P250MB0744D05B8515D9AB954D8A1A8F5B2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>
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 <andreas.rheinhardt@outlook.com>
> ---
> 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".
prev parent reply other threads:[~2024-02-25 10:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-25 1:55 Andreas Rheinhardt
2024-02-25 10:01 ` Mark Thompson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4650b565-9b2a-4023-9c45-9e00086e15e0@jkqxz.net \
--to=sw@jkqxz.net \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git