[FFmpeg-cvslog] seek: Fix crashes in ff_seek_frame_binary if built with latest Clang 14

Martin Storsjö git at videolan.org
Sun Apr 14 23:24:40 EEST 2024


ffmpeg | branch: release/4.2 | Martin Storsjö <martin at martin.st> | Mon Oct 18 12:31:38 2021 +0300| [63b1813119d0bac9cca552f115d51ca4fe149f62] | committer: Michael Niedermayer

seek: Fix crashes in ff_seek_frame_binary if built with latest Clang 14

Passing an uninitialized variable as argument to a function is
undefined behaviour (UB). The compiler can assume that UB does not
happen.

Hence, the compiler can assume that the variables are never
uninitialized when passed as argument, which means that the codepaths
that initializes them must be taken.

In ff_seek_frame_binary, this means that the compiler can assume
that the codepaths that initialize pos_min and pos_max are taken,
which means that the conditions "if (sti->index_entries)" and
"if (index >= 0)" can be optimized out.

Current Clang git versions (upcoming Clang 14) enabled an optimization
that does this, which broke the current version of this function
(which intentionally left the variables uninitialized, but silencing
warnings about being uninitialized). See [1] for discussion on
the matter.

[1] https://reviews.llvm.org/D105169#3069555

Signed-off-by: Martin Storsjö <martin at martin.st>
(cherry picked from commit ab792634197e364ca1bb194f9abe36836e42f12d)
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=63b1813119d0bac9cca552f115d51ca4fe149f62
---

 libavformat/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4067d55fa1..2143d9fb59 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2183,7 +2183,7 @@ int ff_seek_frame_binary(AVFormatContext *s, int stream_index,
                          int64_t target_ts, int flags)
 {
     const AVInputFormat *avif = s->iformat;
-    int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit;
+    int64_t pos_min = 0, pos_max = 0, pos, pos_limit;
     int64_t ts_min, ts_max, ts;
     int index;
     int64_t ret;



More information about the ffmpeg-cvslog mailing list