tools/target_{dec,enc,swr,sws}_fuzzer: restore CPU flags on every run

The fuzzed input can call av_force_cpu_flags(0), which changes process
global state that nothing ever restores. Every later input handled by
the same process then runs with the CPU flags cleared, so runs are not
independent of each other, which is critical for fuzzing. That also
breaks reproduction. A crash found after some earlier input cleared the
flags does not happen when the minimized input is replayed on its own,
because the replay starts with the flags detected for the host.

This might invalidate some already found test vectors, but will find
them quickly again given the corpus is primed already.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
This commit is contained in:
Kacper Michajłow committed 2026-09-24 08:43:09 +00:00
1 parent c952167614
commit 6c47bc66a4
4 files changed
+48

No files matched your search

+12
View File
@@ -174,6 +174,16 @@ static int fuzz_get_buffer2(AVCodecContext *ctx, AVFrame *frame, int flags)
}
}
static void reset_cpu_flags(void)
{
static int default_cpu_flags = -1;
if (default_cpu_flags < 0)
default_cpu_flags = av_get_cpu_flags();
av_force_cpu_flags(default_cpu_flags);
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
uint64_t maxpixels_per_frame = 4096 * 4096;
uint64_t maxpixels;
@@ -194,6 +204,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
uint64_t flushpattern = -1;
AVDictionary *opts = NULL;
reset_cpu_flags();
if (!c) {
#ifdef FFMPEG_DECODER
#define DECODER_SYMBOL0(CODEC) ff_##CODEC##_decoder
+12
View File
@@ -70,6 +70,16 @@ static int encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt)
av_assert0(0);
}
static void reset_cpu_flags(void)
{
static int default_cpu_flags = -1;
if (default_cpu_flags < 0)
default_cpu_flags = av_get_cpu_flags();
av_force_cpu_flags(default_cpu_flags);
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
uint64_t maxpixels_per_frame = 512 * 512;
uint64_t maxpixels;
@@ -80,6 +90,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
AVDictionary *opts = NULL;
uint64_t ec_pixels = 0;
reset_cpu_flags();
if (!c) {
#define ENCODER_SYMBOL0(CODEC) ff_##CODEC##_encoder
#define ENCODER_SYMBOL(CODEC) ENCODER_SYMBOL0(CODEC)
+12
View File
@@ -67,6 +67,16 @@ static const AVChannelLayout layouts[]={
AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK ,
};
static void reset_cpu_flags(void)
{
static int default_cpu_flags = -1;
if (default_cpu_flags < 0)
default_cpu_flags = av_get_cpu_flags();
av_force_cpu_flags(default_cpu_flags);
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
struct SwrContext * swr= NULL;
AVChannelLayout in_ch_layout = AV_CHANNEL_LAYOUT_MONO, out_ch_layout = AV_CHANNEL_LAYOUT_MONO;
@@ -85,6 +95,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
int count;
int ret;
reset_cpu_flags();
if (size > 128) {
GetByteContext gbc;
int64_t flags64;
+12
View File
@@ -86,6 +86,16 @@ static void mapres(unsigned *r0, unsigned *r1) {
*r1 = 1 + (*r1 * maxb) / UINT32_MAX;
}
static void reset_cpu_flags(void)
{
static int default_cpu_flags = -1;
if (default_cpu_flags < 0)
default_cpu_flags = av_get_cpu_flags();
av_force_cpu_flags(default_cpu_flags);
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
int srcW= 48, srcH = 48;
int dstW= 48, dstH = 48;
@@ -101,6 +111,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
uint8_t *dst[AV_VIDEO_MAX_PLANES] = { 0 };
struct SwsContext *sws = NULL;
reset_cpu_flags();
if (size > 128) {
GetByteContext gbc;
int64_t flags64;