PR #24695 opened by Marvin Scholz (ePirat) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24695 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24695.patch
# Summary of changes Add a new macro, FF_MEM_DEFINED, to mark memory as intialized for MSan/Valgrind and use it to mark the memory initialized by the inline assembly in x86 h264 cabac code as initialized, to silence false positive errors. >From 242d32ec605c2ef5d372ede35d4a03b8554fc6f8 Mon Sep 17 00:00:00 2001 From: Marvin Scholz <[email protected]> Date: Fri, 25 Sep 2026 17:37:15 +0000 Subject: [PATCH 1/2] lavu/sanitizer: add FF_MEM_DEFINED Add FF_MEM_DEFINED to mark a piece of memory as defined, useful to silence false-positives where memory is initialized in inline asm. --- libavutil/sanitizer.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavutil/sanitizer.h b/libavutil/sanitizer.h index 35dece3b26..64feb3b113 100644 --- a/libavutil/sanitizer.h +++ b/libavutil/sanitizer.h @@ -56,15 +56,18 @@ #define FF_ASAN_UNPOISON(ptr, size) ((void)(ptr), (void)(size)) #endif -/* Mark memory as uninitialized. */ +/* Mark memory as initialized/uninitialized. */ #if HAVE_MSAN #include <sanitizer/msan_interface.h> #define FF_MEM_UNDEFINED(ptr, size) __msan_allocated_memory(ptr, size) +#define FF_MEM_DEFINED(ptr, size) __msan_unpoison(ptr, size) #elif CONFIG_MEMORY_POISONING && HAVE_VALGRIND_MEMCHECK_H #include <valgrind/memcheck.h> #define FF_MEM_UNDEFINED(ptr, size) VALGRIND_MAKE_MEM_UNDEFINED(ptr, size) +#define FF_MEM_DEFINED(ptr, size) VALGRIND_MAKE_MEM_DEFINED(ptr, size) #else #define FF_MEM_UNDEFINED(ptr, size) ((void)(ptr), (void)(size)) +#define FF_MEM_DEFINED(ptr, size) ((void)(ptr), (void)(size)) #endif #endif /* AVUTIL_SANITIZER_H */ -- 2.52.0 >From a8b84c2063b34ad268fa7b9f8d1d52bdf8687fc7 Mon Sep 17 00:00:00 2001 From: Marvin Scholz <[email protected]> Date: Fri, 25 Sep 2026 17:38:54 +0000 Subject: [PATCH 2/2] lavc/h264: x86: silence MSan false-positive in cabac Mark the memory initialized by the inline assembly as initialized to silence the incorrect memory sanitizer errors when running cabac fate tests. To reproduce, build with clang-msan toolchain and run: make fate-h264-conformance-cabac_mot_frm0_full --- libavcodec/x86/h264_cabac.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavcodec/x86/h264_cabac.c b/libavcodec/x86/h264_cabac.c index ac7d07780c..cccc04ae60 100644 --- a/libavcodec/x86/h264_cabac.c +++ b/libavcodec/x86/h264_cabac.c @@ -28,6 +28,8 @@ #include <stddef.h> +#include "libavutil/sanitizer.h" + #include "libavcodec/cabac.h" #include "cabac.h" @@ -51,6 +53,7 @@ static int decode_significance_x86(CABACContext *c, int max_coeff, int minusindex= 4-(intptr_t)index; int bit; x86_reg coeff_count; + int *orig_index = index; #ifdef BROKEN_RELOCATIONS void *tables; @@ -115,6 +118,7 @@ static int decode_significance_x86(CABACContext *c, int max_coeff, TABLES_ARG : "%"FF_REG_c, "memory" ); + FF_MEM_DEFINED(orig_index, coeff_count * sizeof(*orig_index)); return coeff_count; } @@ -127,6 +131,7 @@ static int decode_significance_8x8_x86(CABACContext *c, x86_reg coeff_count; x86_reg last=0; x86_reg state; + int *orig_index = index; #ifdef BROKEN_RELOCATIONS void *tables; @@ -201,6 +206,7 @@ static int decode_significance_8x8_x86(CABACContext *c, "i"(H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET) TABLES_ARG : "%"FF_REG_c, "memory" ); + FF_MEM_DEFINED(orig_index, coeff_count * sizeof(*orig_index)); return coeff_count; } #endif /* HAVE_X86_7REGS && BROKEN_COMPILER */ -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
