diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-09-18 05:11:57 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-09-19 23:52:37 +0200 |
commit | f440c422b70ce76f225a34ebf168215a432e8d88 (patch) | |
tree | 62b8c418d5724ca8697f23871931a9053f4b8b09 /libswscale/swscale_internal.h | |
parent | a1255a350d4629ca9f0073289ae8e2862aa0d9e1 (diff) | |
download | ffmpeg-f440c422b70ce76f225a34ebf168215a432e8d88.tar.gz |
swscale/swscale: Fix races when using unaligned strides/data
In this case the current code tries to warn once; to do so, it uses
ordinary static ints to store whether the warning has already been
emitted. This is both a data race (and therefore undefined behaviour)
as well as a race condition, because it is really possible for multiple
threads to be the one thread to emit the warning. This is actually
common since the introduction of the new multithreaded scaling API.
This commit fixes this by using atomic integers for the state;
furthermore, these are not static anymore, but rather contained
in the user-facing SwsContext (i.e. the parent SwsContext in case
of slice-threading).
Given that these atomic variables are not intended for synchronization
at all (but only for atomicity, i.e. only to output the warning once),
the atomic operations use memory_order_relaxed.
This affected the nv12, nv21, yuv420, yuv420p10, yuv422, yuv422p10 and
yuv444 filter-overlay FATE-tests.
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libswscale/swscale_internal.h')
-rw-r--r-- | libswscale/swscale_internal.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 0d60dd2e6f..e6e7b934b6 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -21,6 +21,8 @@ #ifndef SWSCALE_SWSCALE_INTERNAL_H #define SWSCALE_SWSCALE_INTERNAL_H +#include <stdatomic.h> + #include "config.h" #include "version.h" @@ -672,6 +674,8 @@ typedef struct SwsContext { unsigned int xyz_scratch_allocated; unsigned int dst_slice_align; + atomic_int stride_unaligned_warned; + atomic_int data_unaligned_warned; } SwsContext; //FIXME check init (where 0) |