From patchwork Wed Jun 26 11:40:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 50158 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ccd2:0:b0:482:c625:d099 with SMTP id q18csp370880vqv; Wed, 26 Jun 2024 04:41:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWUX1bPwA2OphUEDtr4WTtCd/xxtn9auyn5F0af8EeHkffTpK5dbgow9RkACkTrQUs1jSAW0447dzjHT5JWBtgzeOMs237FUb8g3Q== X-Google-Smtp-Source: AGHT+IHDsshAUQ8EVhgqwSAdmiC2TULe59gdSGCfEHWRSc6xkASKMyfX8DukhP1slSPXhcl8lxJA X-Received: by 2002:a17:906:150d:b0:a6f:f1bc:21ce with SMTP id a640c23a62f3a-a7245c4837emr655182566b.47.1719402066157; Wed, 26 Jun 2024 04:41:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719402066; cv=none; d=google.com; s=arc-20160816; b=S31ibX9bUe2CxrS919444JWEarkVwVlRZxqcKShgj1AM72YIByp4c25HJ3ndEyGb01 n2Ftur1sAvNiWd3BTApabtGsOXotjvkE0FQoP1OPYwZqHJcAY1iFu23WsHkcmPX8XLvJ RePGfbqqNnA8cJZvdF5h4qX3irZuese8ZljnFQQFqUjdlgeKb3fGlbFGaajGXtL2uA+y BJEO8Ms1z2evDip3ti8JQ1/M2HGNhoYBAoYKkdOZv6INDMbWs3qDQ4qRoiawXgza13QK yCv68OZRxl+oVvljTTRbKiYORLZYC19ikRk/cV598YyvG0wYnwzirUJ21NzayL/gG3vF 7Obw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=tCGbVak3QTzuJ9qqs0GzH/QuJSuD4d/Kg3SDs3d40ek=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=Uto1riL1eyMv/xqo1Vg7KLp2HjFW+IkNhj7g/yiBOBbBIszQLVciwiNTiBIMSlcNfA VZp4QkvD4Hq6537K88i/ayNVxJ6FGCkvEFhLgdP3SycQqd968lHYPlHR/of+71DTeAst hWWabgwbDyLsnBEF0RBTCA7BNwmNa2kqIUkv3+IDl1Bulb4PgnkZPeV8U6/d07ubQw77 MUyZEy0BqsOGasED/yUkqZ7HqH6KTzW0TSZ5JQCdpllxTgD1TlvDvQJcYMabbBqWmq1X M6gVasjpaUSgHIUZvanPsP80la7YSV4wg4p9528IDajUzpsdp75UJcM0F5REz5j7vkYS bihQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=AV2N9qGi; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a7244c1492csi415681666b.819.2024.06.26.04.41.05; Wed, 26 Jun 2024 04:41:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=AV2N9qGi; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 307B368C0EB; Wed, 26 Jun 2024 14:41:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 737A768C0EB for ; Wed, 26 Jun 2024 14:40:55 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 979ADFF804 for ; Wed, 26 Jun 2024 11:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1719402054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=MIxZKA6m6rRXWGjIrZvlfnEepZ/RUI232t+uIOopZEY=; b=AV2N9qGimJQfsjRst8Off+gGefzZcuoMjITz+V3rRALmwK29ngAc63WuBaijyumoWsjSw/ DPQLBpb6uJqxs5CQUwx0xSoDLP3P3WnM0tjW1u+Y3sIxgEmZHx0jTa5DnWVixfE2Bnsuwr 8FLiaPgrJpV02TYbEr+4EGVgj7Xz4pdWjhA2qZNV9Q9CPC8zkvZkj53z9muxttOYFA1lLb fHlS3GxiPrRGLKGwXehB3qnlJk7dhQT7o/ROfr0/48KH1bOQjJx+lie0ZZSzhmCo5gK+zd QnHn13EqLKc4LHCFD0camy43807w4Tcfradcl6T5QZz8cfAMW+5LOYjA3SAL4Q== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 26 Jun 2024 13:40:53 +0200 Message-ID: <20240626114053.230503-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH] add tools/target_swr_fuzzer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: msuQH4YHizZ3 Signed-off-by: Michael Niedermayer --- Makefile | 2 + tools/Makefile | 3 + tools/target_swr_fuzzer.c | 161 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 tools/target_swr_fuzzer.c diff --git a/Makefile b/Makefile index 4c3af09fec4..b350d7748f5 100644 --- a/Makefile +++ b/Makefile @@ -70,6 +70,8 @@ tools/target_io_dem_fuzzer$(EXESUF): tools/target_io_dem_fuzzer.o $(FF_DEP_LIBS) tools/target_sws_fuzzer$(EXESUF): tools/target_sws_fuzzer.o $(FF_DEP_LIBS) $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(LIBFUZZER_PATH) +tools/target_swr_fuzzer$(EXESUF): tools/target_swr_fuzzer.o $(FF_DEP_LIBS) + $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(LIBFUZZER_PATH) tools/enum_options$(EXESUF): ELIBS = $(FF_EXTRALIBS) tools/enum_options$(EXESUF): $(FF_DEP_LIBS) diff --git a/tools/Makefile b/tools/Makefile index 2a11fa0ae62..7ae6e3cb75d 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -23,6 +23,9 @@ tools/target_io_dem_fuzzer.o: tools/target_dem_fuzzer.c tools/target_sws_fuzzer.o: tools/target_sws_fuzzer.c $(COMPILE_C) +tools/target_swr_fuzzer.o: tools/target_swr_fuzzer.c + $(COMPILE_C) + tools/enc_recon_frame_test$(EXESUF): tools/decode_simple.o tools/venc_data_dump$(EXESUF): tools/decode_simple.o tools/scale_slice_test$(EXESUF): tools/decode_simple.o diff --git a/tools/target_swr_fuzzer.c b/tools/target_swr_fuzzer.c new file mode 100644 index 00000000000..f235b5453ec --- /dev/null +++ b/tools/target_swr_fuzzer.c @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2024 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" +#include "libavutil/avassert.h" +#include "libavutil/avstring.h" +#include "libavutil/cpu.h" +#include "libavutil/imgutils.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/mem.h" +#include "libavutil/opt.h" + +#include "libavcodec/bytestream.h" + +#include "libswresample/swresample.h" + +#define SWR_CH_MAX 32 + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); + +static const enum AVSampleFormat formats[] = { + AV_SAMPLE_FMT_U8, + AV_SAMPLE_FMT_U8P, + AV_SAMPLE_FMT_S16, + AV_SAMPLE_FMT_S16P, + AV_SAMPLE_FMT_S32, + AV_SAMPLE_FMT_S32P, + AV_SAMPLE_FMT_FLT, + AV_SAMPLE_FMT_FLTP, + AV_SAMPLE_FMT_DBL, + AV_SAMPLE_FMT_DBLP, +}; + +static const AVChannelLayout layouts[]={ + AV_CHANNEL_LAYOUT_MONO , + AV_CHANNEL_LAYOUT_STEREO , + AV_CHANNEL_LAYOUT_2_1 , + AV_CHANNEL_LAYOUT_SURROUND , + AV_CHANNEL_LAYOUT_4POINT0 , + AV_CHANNEL_LAYOUT_2_2 , + AV_CHANNEL_LAYOUT_QUAD , + AV_CHANNEL_LAYOUT_5POINT0 , + AV_CHANNEL_LAYOUT_5POINT1 , + AV_CHANNEL_LAYOUT_5POINT0_BACK , + AV_CHANNEL_LAYOUT_5POINT1_BACK , + AV_CHANNEL_LAYOUT_7POINT0 , + AV_CHANNEL_LAYOUT_7POINT1 , + AV_CHANNEL_LAYOUT_7POINT1_WIDE , +}; + +static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples){ + if(av_sample_fmt_is_planar(format)){ + int i; + int plane_size= av_get_bytes_per_sample(format&0xFF)*samples; + format&=0xFF; + for(i=0; i 128) { + GetByteContext gbc; + int64_t flags64; + + size -= 128; + bytestream2_init(&gbc, data + size, 128); + in_sample_rate = bytestream2_get_le16(&gbc) + 1; + out_sample_rate = bytestream2_get_le16(&gbc) + 1; + in_sample_fmt = formats[bytestream2_get_byte(&gbc) % FF_ARRAY_ELEMS(formats)]; + out_sample_fmt = formats[bytestream2_get_byte(&gbc) % FF_ARRAY_ELEMS(formats)]; + av_channel_layout_copy(& in_ch_layout, &layouts[bytestream2_get_byte(&gbc) % FF_ARRAY_ELEMS(layouts)]); + av_channel_layout_copy(&out_ch_layout, &layouts[bytestream2_get_byte(&gbc) % FF_ARRAY_ELEMS(layouts)]); + + out_sample_nb = bytestream2_get_le32(&gbc); + + flags64 = bytestream2_get_le64(&gbc); + if (flags64 & 0x10) + av_force_cpu_flags(0); + } else { + av_channel_layout_copy(& in_ch_layout, &layouts[0]); + av_channel_layout_copy(&out_ch_layout, &layouts[0]); + } + + in_ch_count= in_ch_layout.nb_channels; + out_ch_count= out_ch_layout.nb_channels; + av_channel_layout_describe(& in_ch_layout, in_layout_string, sizeof( in_layout_string)); + av_channel_layout_describe(&out_ch_layout, out_layout_string, sizeof(out_layout_string)); + + fprintf(stderr, "%s %d %s -> %s %d %s\n", + av_get_sample_fmt_name( in_sample_fmt), in_sample_rate, in_layout_string, + av_get_sample_fmt_name(out_sample_fmt), out_sample_rate, out_layout_string); + + if (swr_alloc_set_opts2(&swr, &out_ch_layout, out_sample_fmt, out_sample_rate, + &in_ch_layout, in_sample_fmt, in_sample_rate, + 0, 0) < 0) { + fprintf(stderr, "Failed swr_alloc_set_opts2()\n"); + goto end; + } + + if(swr_init(swr) < 0) { + fprintf(stderr, "Failed swr_init()\n"); + goto end; + } + + in_sample_nb = size / (in_ch_count * av_get_bytes_per_sample(in_sample_fmt)); + out_sample_nb = out_sample_nb % (av_rescale(in_sample_nb, 2*out_sample_rate, in_sample_rate) + 1); + + out_data = av_malloc(out_sample_nb * out_ch_count * av_get_bytes_per_sample(out_sample_fmt)); + if (!out_data) + goto end; + + setup_array(ain , (uint8_t*)data, in_sample_fmt, in_sample_nb); + setup_array(aout, out_data, out_sample_fmt, out_sample_nb); + + count = swr_convert(swr, aout, out_sample_nb, (const uint8_t **)ain, in_sample_nb); + + av_freep(&out_data); + +end: + swr_free(&swr); + + return 0; +}