This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 9fc3af90c4287bfea962729e9b85335b8fa20422 Author: Kacper Michajłow <[email protected]> AuthorDate: Sun Sep 13 03:29:04 2026 +0200 Commit: Kacper Michajłow <[email protected]> CommitDate: Thu Sep 24 18:08:16 2026 +0000 avutil/mem: keep poisoned memory undefined for MSan and Valgrind CONFIG_MEMORY_POISONING fills fresh allocations with a pattern. Memory checkers that track initialization take that fill for real data and stop reporting reads of it, which defeats the purpose of the fill. MSan is told in every MSan build, its cost is expected there. The Valgrind client requests are only compiled in memory poisoning builds, since they would otherwise cost every allocation a few instructions in any ordinary build made where the Valgrind headers are installed. Signed-off-by: Kacper Michajłow <[email protected]> --- configure | 2 ++ libavutil/mem.c | 21 ++++++++++------ libavcodec/wma_common.h => libavutil/sanitizer.h | 31 ++++++++++++++++++------ 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/configure b/configure index 516a7c84c1..c588508f8a 100755 --- a/configure +++ b/configure @@ -2472,6 +2472,7 @@ HEADERS_LIST=" termios_h udplite_h unistd_h + valgrind_memcheck_h valgrind_valgrind_h windows_h winsock2_h @@ -6963,6 +6964,7 @@ check_headers sys/time.h check_headers sys/un.h check_headers termios.h check_headers unistd.h +check_headers valgrind/memcheck.h check_headers valgrind/valgrind.h check_func_headers VideoToolbox/VTCompressionSession.h VTCompressionSessionPrepareToEncodeFrames -framework VideoToolbox check_func_headers VideoToolbox/VideoToolbox.h VTDecompressionSessionDecodeFrame -framework VideoToolbox diff --git a/libavutil/mem.c b/libavutil/mem.c index e8e5f5f2e2..a796d4dde1 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -45,6 +45,7 @@ #include "intreadwrite.h" #include "macros.h" #include "mem.h" +#include "sanitizer.h" #ifdef MALLOC_PREFIX @@ -66,6 +67,14 @@ void free(void *ptr); #define FF_MEMORY_POISON 0x2a +static void poison_memory(void *ptr, size_t size) +{ +#if CONFIG_MEMORY_POISONING + memset(ptr, FF_MEMORY_POISON, size); +#endif + FF_MEM_UNDEFINED(ptr, size); +} + /* NOTE: if you want to override these functions with your own * implementations (not recommended) you have to link libav* as * dynamic libraries and remove -Wl,-Bsymbolic from the linker flags. @@ -145,10 +154,8 @@ void *av_malloc(size_t size) size = 1; ptr= av_malloc(1); } -#if CONFIG_MEMORY_POISONING if (ptr) - memset(ptr, FF_MEMORY_POISON, size); -#endif + poison_memory(ptr, size); return ptr; } @@ -163,10 +170,8 @@ void *av_realloc(void *ptr, size_t size) #else ret = realloc(ptr, size + !size); #endif -#if CONFIG_MEMORY_POISONING if (ret && !ptr) - memset(ret, FF_MEMORY_POISON, size); -#endif + poison_memory(ret, size); return ret; } @@ -347,8 +352,8 @@ void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, tab_elem_data = (uint8_t *)*tab_ptr + (*nb_ptr) * elem_size; if (elem_data) memcpy(tab_elem_data, elem_data, elem_size); - else if (CONFIG_MEMORY_POISONING) - memset(tab_elem_data, FF_MEMORY_POISON, elem_size); + else + poison_memory(tab_elem_data, elem_size); }, { av_freep(tab_ptr); *nb_ptr = 0; diff --git a/libavcodec/wma_common.h b/libavutil/sanitizer.h similarity index 58% copy from libavcodec/wma_common.h copy to libavutil/sanitizer.h index 55404afc45..644b74f844 100644 --- a/libavcodec/wma_common.h +++ b/libavutil/sanitizer.h @@ -1,6 +1,4 @@ /* - * common code shared by all WMA variants - * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,10 +16,29 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVCODEC_WMA_COMMON_H -#define AVCODEC_WMA_COMMON_H +#ifndef AVUTIL_SANITIZER_H +#define AVUTIL_SANITIZER_H + +#include "config.h" + +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) +#define HAVE_MSAN 1 +#endif +#endif +#ifndef HAVE_MSAN +#define HAVE_MSAN 0 +#endif -int ff_wma_get_frame_len_bits(int sample_rate, int version, - unsigned int decode_flags); +/* Mark memory as uninitialized. */ +#if HAVE_MSAN +#include <sanitizer/msan_interface.h> +#define FF_MEM_UNDEFINED(ptr, size) __msan_allocated_memory(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) +#else +#define FF_MEM_UNDEFINED(ptr, size) ((void)(ptr), (void)(size)) +#endif -#endif /* AVCODEC_WMA_COMMON_H */ +#endif /* AVUTIL_SANITIZER_H */ -- To stop receiving notification emails like this one, please contact [email protected]. _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
