From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id AD645493AA for ; Wed, 7 Aug 2024 15:35:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 04C8568DB07; Wed, 7 Aug 2024 18:35:24 +0300 (EEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D4FD968D367 for ; Wed, 7 Aug 2024 18:35:16 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 1976360004 for ; Wed, 7 Aug 2024 15:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1723044916; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0pbe39Jf86mWY+bizWnfnK4wjZNYEKdTJfRis+xcfMw=; b=jYSrYziZC2Dorgj03JZaPTzSYR9zcnOu8xMWpC+651J0AgEzn3G3UShfmdcdRGKqlKAsSZ JSrTUhqWVHE8SB/rAZoNIiE0UDp401YOjtlgY5Mm5jwqKFe6VikyJvmCygOp2yV6EF9nrk IgBaPTPNezhEvelB/2cBNmmbkMBj7z75dJPE8Opsz3NW67oYajqJJTMU+z+GvQMS2Npasu Vxzz02wQESqDR5X1ncPWxRqIFDllYDAJ0EnNEN6WxY6URGKjIKVxyxj08/iGV3+hCeDwLq KeeL+NRpmgFn/5eepYwJUyRmbgkpEYoKfm/RK5gh9vXtBnAXF0CTyT9d7HVe1Q== Date: Wed, 7 Aug 2024 17:35:14 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20240807153514.GT4991@pb2> References: <20240626114053.230503-1-michael@niedermayer.cc> <1352e042-9fc6-4c10-b7e8-2a643759b249@gmail.com> MIME-Version: 1.0 In-Reply-To: <1352e042-9fc6-4c10-b7e8-2a643759b249@gmail.com> X-GND-Sasl: michael@niedermayer.cc Subject: Re: [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 Content-Type: multipart/mixed; boundary="===============2427881910595214931==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============2427881910595214931== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="xSEMfpWWEi9ZGPb2" Content-Disposition: inline --xSEMfpWWEi9ZGPb2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 26, 2024 at 10:35:32AM -0300, James Almer wrote: > On 6/26/2024 8:40 AM, Michael Niedermayer wrote: > > 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 > >=20 > > 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_L= IBS) > > + $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(= LIBFUZZER_PATH) > > tools/enum_options$(EXESUF): ELIBS =3D $(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= =2Ec > > 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[] =3D { > > + 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[]=3D{ >=20 > Dunno if it matters to save space, but since these are all native layouts > you could store the masks here as an array of uint64_t, and use > av_channel_layout_from_mask() instead of av_channel_layout_copy() below. I think we should keep the more generic type >=20 > > + 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 , >=20 > Add AV_CHANNEL_LAYOUT_22POINT2 too, which is processed as a 9 channels > layout. And AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK to test the top channels > rematrix code. added >=20 > > +}; > > + > > +static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AV= SampleFormat format, int samples){ > > + if(av_sample_fmt_is_planar(format)){ > > + int i; > > + int plane_size=3D av_get_bytes_per_sample(format&0xFF)*samples; > > + format&=3D0xFF; > > + for(i=3D0; i > + out[i]=3D in + i*plane_size; > > + } > > + }else{ > > + out[0]=3D in; > > + } > > +} > > + > > +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { > > + const uint8_t *end =3D data + size; > > + struct SwrContext * swr=3D NULL; > > + AVChannelLayout in_ch_layout =3D { 0 }, out_ch_layout =3D { 0 }; > > + enum AVSampleFormat in_sample_fmt =3D AV_SAMPLE_FMT_S16P; > > + enum AVSampleFormat out_sample_fmt =3D AV_SAMPLE_FMT_S16P; > > + int in_sample_rate =3D 44100; > > + int out_sample_rate =3D 44100; > > + int in_ch_count, out_ch_count; > > + char in_layout_string[256]; > > + char out_layout_string[256]; > > + uint8_t * ain[SWR_CH_MAX]; > > + uint8_t *aout[SWR_CH_MAX]; > > + uint8_t *out_data; > > + int in_sample_nb; > > + int out_sample_nb =3D size; > > + int count; > > + > > + if (size > 128) { > > + GetByteContext gbc; > > + int64_t flags64; > > + > > + size -=3D 128; > > + bytestream2_init(&gbc, data + size, 128); > > + in_sample_rate =3D bytestream2_get_le16(&gbc) + 1; > > + out_sample_rate =3D bytestream2_get_le16(&gbc) + 1; > > + in_sample_fmt =3D formats[bytestream2_get_byte(&gbc) % FF_AR= RAY_ELEMS(formats)]; > > + out_sample_fmt =3D formats[bytestream2_get_byte(&gbc) % FF_AR= RAY_ELEMS(formats)]; > > + av_channel_layout_copy(& in_ch_layout, &layouts[bytestream2_g= et_byte(&gbc) % FF_ARRAY_ELEMS(layouts)]); > > + av_channel_layout_copy(&out_ch_layout, &layouts[bytestream2_g= et_byte(&gbc) % FF_ARRAY_ELEMS(layouts)]); > > + > > + out_sample_nb =3D bytestream2_get_le32(&gbc); > > + > > + flags64 =3D 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=3D in_ch_layout.nb_channels; > > + out_ch_count=3D out_ch_layout.nb_channels; > > + av_channel_layout_describe(& in_ch_layout, in_layout_string, size= of( in_layout_string)); > > + av_channel_layout_describe(&out_ch_layout, out_layout_string, size= of(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, o= ut_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 =3D size / (in_ch_count * av_get_bytes_per_sample(in= _sample_fmt)); > > + out_sample_nb =3D out_sample_nb % (av_rescale(in_sample_nb, 2*out_= sample_rate, in_sample_rate) + 1); > > + > > + out_data =3D 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); >=20 > You could use av_samples_alloc() to fill both ain and aout. av_samples_alloc() clears the buffers, only fuzzing with silence seems not = correct. next patch will use av_samples_fill_arrays() thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Complexity theory is the science of finding the exact solution to an approximation. Benchmarking OTOH is finding an approximation of the exact --xSEMfpWWEi9ZGPb2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEKAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZrOULAAKCRBhHseHBAsP q0eEAJ41qnTupT1QkHuhtkIXhPRhH3WpYwCfTg4Xuex0F4AG5X+a6U1YMQtvP0E= =HJxD -----END PGP SIGNATURE----- --xSEMfpWWEi9ZGPb2-- --===============2427881910595214931== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". --===============2427881910595214931==--