From patchwork Thu May 6 17:04:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedaa X-Patchwork-Id: 27627 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp194709iof; Thu, 6 May 2021 10:05:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxu5i5rZHb3tcUotXtd9cizuAgmx1KeWU+w76lIdL9vcHJ4qf7ABFGmLyfFmd799hkJmKwV X-Received: by 2002:a17:906:2408:: with SMTP id z8mr5764515eja.60.1620320748482; Thu, 06 May 2021 10:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620320748; cv=none; d=google.com; s=arc-20160816; b=HufWoKE8bcoKFkfh7+bb+Wp/Ve0BWHVrooexVWx7NbPjRa2tSfpfaFIjKJcGS7vC7N DBBPCZLXGGkUHbgDkoR1zD8H4ZzTWyiugZHDoOAvpQcHFj5hVpJu0K/RsICEsUky4Lon +ha+nMGPXGkWKDvz95FBVVwLJg7Jx/yqTgNGcAows14/62I38DohnmQoYbXFkcScAg9J 9wv1CwOxkSfcZIsUxZ9X6M9XWEbkGUPspqZkbKT4NzyGoDyzVO4PfN5l0/YbEm+b5VOs h+WWMqQ22AqIvOW0W2g0LGDzW9JQMyEKO2YAoRawHhiEH4W6f7nCUO3Ss29amb9SYr+d fJTg== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=dlf60GmWz8nufwOTEuTt63GZ9XL0ON/SXpdbukAiKdg=; b=SE9ZJ7xvNjFq5iKvA/V3W65S8m36MOz41Z2P03VS3pwnI2rpj8gsetQym4uUveGJaJ YVnIKvP/CI1aLhJLRK9YxFgBNRNMPOgffCClxrtDz5ho7bwGuVf+/JSX6+6BoLcE7qku GSaySHxLRhrWPraq/xDxtae1DG2tzten+tsBkkwE6J78qzpGPSu2zw6IBpK7rh0MEEbF RGHg+evuib9kVAuGVKftqfR2waPnmr7GdFJG/L7MMbc90KWfLMkZ3DffpJ7YpI6GxoK1 nVnoTNRvpxGpUEUqJs4qkP8HM0Tk6BTqj+cj44zTGUzXyiCUsZLNTNGaXG3aeCGNP1kb p/eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@riseup.net header.s=squak header.b=NR4kvfRl; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=riseup.net Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l11si2686680edv.444.2021.05.06.10.05.47; Thu, 06 May 2021 10:05:48 -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=@riseup.net header.s=squak header.b=NR4kvfRl; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=riseup.net Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 991AE6806DC; Thu, 6 May 2021 20:05:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EB046680211 for ; Thu, 6 May 2021 20:05:36 +0300 (EEST) Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "Sectigo RSA Domain Validation Secure Server CA" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4Fbg2562v1zF3Lm for ; Thu, 6 May 2021 10:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1620320733; bh=f3rZ77LwPqPmB+0T9AT7otmacbA6wHQ7UUmdVEu9o/s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NR4kvfRlXCSA4HPSGr9qyjGUNEx0fAs5+pZO3MdSItn+H0NrL4xGjplbnbvLsfYar E72LbWH5EC9qrv3+r1NG37cYQNLK7iid0TVFvtN1JOruVxSAcS1ajzFnljFXsVTF/5 QAXd7Np7uKUDORHFopnkEXQruXWR9n65GbfBe3do= X-Riseup-User-ID: 5A6F17B2F6BCD84EDF110BEFE2AAEDB35EDAA19F0C34B1DF5686AD56E4AC3AE5 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4Fbg2467k7z5vff for ; Thu, 6 May 2021 10:05:32 -0700 (PDT) From: Vedaa To: ffmpeg-devel@ffmpeg.org Date: Thu, 6 May 2021 22:34:50 +0530 Message-Id: <20210506170450.463184-1-vedaa@riseup.net> In-Reply-To: <20210503132833.GU4777@pb2> References: <20210503132833.GU4777@pb2> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCHv2] fate/integer.c: Connect test to 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: 7G8ZCxQkJBZn Hi, I have made the requisite changes. --- Makefile | 2 ++ libavutil/tests/integer.c | 21 ++----------------- libavutil/tests/integer.h | 43 +++++++++++++++++++++++++++++++++++++++ tools/Makefile | 3 +++ tools/target_int_fuzzer.c | 35 +++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 19 deletions(-) create mode 100644 libavutil/tests/integer.h create mode 100644 tools/target_int_fuzzer.c diff --git a/Makefile b/Makefile index 7e9d8b08c3..92fe8cac65 100644 --- a/Makefile +++ b/Makefile @@ -62,6 +62,8 @@ tools/target_dem_fuzzer$(EXESUF): tools/target_dem_fuzzer.o $(FF_DEP_LIBS) tools/target_io_dem_fuzzer$(EXESUF): tools/target_io_dem_fuzzer.o $(FF_DEP_LIBS) $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(LIBFUZZER_PATH) +tools/target_int_fuzzer$(EXESUF): tools/target_int_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/libavutil/tests/integer.c b/libavutil/tests/integer.c index d2c8f2a903..1d28a3aa93 100644 --- a/libavutil/tests/integer.c +++ b/libavutil/tests/integer.c @@ -18,31 +18,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include - -#include "libavutil/avassert.h" -#include "libavutil/integer.h" -#include "libavutil/intmath.h" +#include "libavutil/tests/integer.h" int main(void){ int64_t a,b; for(a=7; a<256*256*256; a+=13215){ for(b=3; b<256*256*256; b+=27118){ - AVInteger ai= av_int2i(a); - AVInteger bi= av_int2i(b); - - av_assert0(av_i2int(ai) == a); - av_assert0(av_i2int(bi) == b); - av_assert0(av_i2int(av_add_i(ai,bi)) == a+b); - av_assert0(av_i2int(av_sub_i(ai,bi)) == a-b); - av_assert0(av_i2int(av_mul_i(ai,bi)) == a*b); - av_assert0(av_i2int(av_shr_i(ai, 9)) == a>>9); - av_assert0(av_i2int(av_shr_i(ai,-9)) == a<<9); - av_assert0(av_i2int(av_shr_i(ai, 17)) == a>>17); - av_assert0(av_i2int(av_shr_i(ai,-17)) == a<<17); - av_assert0(av_log2_i(ai) == av_log2(a)); - av_assert0(av_i2int(av_div_i(ai,bi)) == a/b); + TestInteger(a,b); } } return 0; diff --git a/libavutil/tests/integer.h b/libavutil/tests/integer.h new file mode 100644 index 0000000000..4dbd239ac4 --- /dev/null +++ b/libavutil/tests/integer.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2004 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 + +#include "libavutil/avassert.h" +#include "libavutil/integer.h" +#include "libavutil/intmath.h" + +static inline void TestInteger(int64_t a, int64_t b) +{ + AVInteger ai= av_int2i(a); + AVInteger bi= av_int2i(b); + + av_assert0(av_i2int(ai) == a); + av_assert0(av_i2int(bi) == b); + av_assert0(av_i2int(av_add_i(ai,bi)) == a+b); + av_assert0(av_i2int(av_sub_i(ai,bi)) == a-b); + av_assert0(av_i2int(av_mul_i(ai,bi)) == a*b); + av_assert0(av_i2int(av_shr_i(ai, 9)) == a>>9); + av_assert0(av_i2int(av_shr_i(ai,-9)) == a<<9); + av_assert0(av_i2int(av_shr_i(ai, 17)) == a>>17); + av_assert0(av_i2int(av_shr_i(ai,-17)) == a<<17); + av_assert0(av_log2_i(ai) == av_log2(a)); + av_assert0(av_i2int(av_div_i(ai,bi)) == a/b); +} diff --git a/tools/Makefile b/tools/Makefile index 82baa8eadb..fde7f08984 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -17,6 +17,9 @@ tools/target_dem_fuzzer.o: tools/target_dem_fuzzer.c tools/target_io_dem_fuzzer.o: tools/target_dem_fuzzer.c $(COMPILE_C) -DIO_FLAT=0 +tools/target_int_fuzzer.o: tools/target_int_fuzzer.c + $(COMPILE_C) + OUTDIRS += tools clean:: diff --git a/tools/target_int_fuzzer.c b/tools/target_int_fuzzer.c new file mode 100644 index 0000000000..811f410b1a --- /dev/null +++ b/tools/target_int_fuzzer.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2004 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 +#include + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); + +int LLVMFuzzerTestOneInput( const uint8_t *data, size_t size ) { + if (size < 2 * sizeof(int64_t)) + return 1; + + int64_t a,b; + a = AV_RB64(data); + b = AV_RB64(data + sizeof(int64_t)); + TestInteger(a,b); + return 0; +}