From 0cba0117f37a401d0a190efaa6380463a9f2435e Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Mon, 17 Jun 2019 13:20:29 -0700 Subject: [PATCH] [libfdk-aac] adding libfdk-aac (#2480) * [glossary] explain cross-pollination * [glossary] explain cross-pollination * add fdk-aac * move fdk-aac to libfdk-aac * [libfdk-aac] add -fno-sanitize=shift * [libfdk-aac] update the contact email, change the repository, disable ubsan's shift-base instead of shift * [libfdk-aac] change the homepage link * [libfdk-aac] add one CC entry --- projects/libfdk-aac/Dockerfile | 20 ++++++++ projects/libfdk-aac/aacDecoder_ConfigRaw.cpp | 39 ++++++++++++++ .../libfdk-aac/aacDecoder_DecodeFrame.cpp | 51 +++++++++++++++++++ projects/libfdk-aac/aacDecoder_Open.cpp | 36 +++++++++++++ projects/libfdk-aac/build.sh | 31 +++++++++++ projects/libfdk-aac/project.yaml | 4 ++ 6 files changed, 181 insertions(+) create mode 100644 projects/libfdk-aac/Dockerfile create mode 100644 projects/libfdk-aac/aacDecoder_ConfigRaw.cpp create mode 100644 projects/libfdk-aac/aacDecoder_DecodeFrame.cpp create mode 100644 projects/libfdk-aac/aacDecoder_Open.cpp create mode 100755 projects/libfdk-aac/build.sh create mode 100644 projects/libfdk-aac/project.yaml diff --git a/projects/libfdk-aac/Dockerfile b/projects/libfdk-aac/Dockerfile new file mode 100644 index 000000000..441bcf965 --- /dev/null +++ b/projects/libfdk-aac/Dockerfile @@ -0,0 +1,20 @@ +# Copyright 2019 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +FROM gcr.io/oss-fuzz-base/base-builder +MAINTAINER kcc@google.com +RUN git clone --depth 1 https://android.googlesource.com/platform/external/aac/ +COPY build.sh *.cpp $SRC/ diff --git a/projects/libfdk-aac/aacDecoder_ConfigRaw.cpp b/projects/libfdk-aac/aacDecoder_ConfigRaw.cpp new file mode 100644 index 000000000..eb6dbdacd --- /dev/null +++ b/projects/libfdk-aac/aacDecoder_ConfigRaw.cpp @@ -0,0 +1,39 @@ +// Copyright 2019 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "aacdecoder_lib.h" +#include + +#define FILEREAD_MAX_LAYERS 1 + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + HANDLE_AACDECODER aacDecoderInfo = NULL; + + UCHAR *conf[FILEREAD_MAX_LAYERS]; + UINT confSize[FILEREAD_MAX_LAYERS]; + + if (Size > 255) return 0; + + aacDecoderInfo = aacDecoder_Open(TT_MP4_ADIF, FILEREAD_MAX_LAYERS); + FDK_ASSERT(aacDecoderInfo != NULL); + + for (UINT layer = 0; layer < FILEREAD_MAX_LAYERS; layer++) { + conf[layer] = const_cast(Data); + confSize[layer] = Size; + } + + aacDecoder_ConfigRaw(aacDecoderInfo, conf, confSize); + aacDecoder_Close(aacDecoderInfo); + return 0; +} diff --git a/projects/libfdk-aac/aacDecoder_DecodeFrame.cpp b/projects/libfdk-aac/aacDecoder_DecodeFrame.cpp new file mode 100644 index 000000000..67b8b764e --- /dev/null +++ b/projects/libfdk-aac/aacDecoder_DecodeFrame.cpp @@ -0,0 +1,51 @@ +// Copyright 2019 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "aacdecoder_lib.h" +#include + +#define FILEREAD_MAX_LAYERS 1 +#define OUT_BUF_SIZE (8 * 2048 * 4) + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + HANDLE_AACDECODER aacDecoderInfo = NULL; + + INT_PCM TimeData[OUT_BUF_SIZE]; + AAC_DECODER_ERROR err; + aacDecoderInfo = aacDecoder_Open(TT_MP4_LOAS, FILEREAD_MAX_LAYERS); + FDK_ASSERT(aacDecoderInfo != NULL); + + const uint8_t *start = Data; + UINT valid, buffer_size; + + do { + valid = buffer_size = Data + Size - start; + err = aacDecoder_Fill(aacDecoderInfo, const_cast(&start), + &buffer_size, &valid); + start += buffer_size - valid; + if (err == AAC_DEC_OK) { + do { + err = aacDecoder_DecodeFrame(aacDecoderInfo, TimeData, OUT_BUF_SIZE, 0); + if (err != AAC_DEC_OK && err != AAC_DEC_NOT_ENOUGH_BITS) { + aacDecoder_Close(aacDecoderInfo); + aacDecoderInfo = NULL; + return 0; + } + } while (err != AAC_DEC_NOT_ENOUGH_BITS); + } + } while (valid > 0); + aacDecoder_Close(aacDecoderInfo); + aacDecoderInfo = NULL; + return 0; +} diff --git a/projects/libfdk-aac/aacDecoder_Open.cpp b/projects/libfdk-aac/aacDecoder_Open.cpp new file mode 100644 index 000000000..e5e2a9c55 --- /dev/null +++ b/projects/libfdk-aac/aacDecoder_Open.cpp @@ -0,0 +1,36 @@ +// Copyright 2019 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "aacdecoder_lib.h" +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + HANDLE_AACDECODER aacDecoderInfo = NULL; + + TRANSPORT_TYPE transportType; + INT nrOfLayers; + + if (Size != 8) return 0; + + transportType = (TRANSPORT_TYPE)(Data[0] + (Data[1] << 8) + (Data[2] << 16) + + (Data[3] << 24)); + nrOfLayers = + (UINT)(Data[4] + (Data[5] << 8) + (Data[6] << 16) + (Data[7] << 24)); + + aacDecoderInfo = aacDecoder_Open(transportType, nrOfLayers); + if (aacDecoderInfo != NULL) { + aacDecoder_Close(aacDecoderInfo); + } + return 0; +} diff --git a/projects/libfdk-aac/build.sh b/projects/libfdk-aac/build.sh new file mode 100755 index 000000000..0de0b4fbd --- /dev/null +++ b/projects/libfdk-aac/build.sh @@ -0,0 +1,31 @@ +#!/bin/bash -eu +# Copyright 2019 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +# Build the lib. +INCLUDES=$(for f in $(find aac -name include); do echo -I $f; done) +# exclude -fno-sanitize=shift-base as there are shallow errors. +EXTRA_FLAGS=-fno-sanitize=shift-base +for f in aac/*/src/*.cpp; do + $CXX $CXXFLAGS $INCLUDES $EXTRA_FLAGS -c $f & +done +wait + +# Build the fuzz targets. +for target_cpp in *.cpp; do + target=$(basename $target_cpp .cpp) + $CXX $CXXFLAGS $EXTRA_FLAGS $target_cpp $INCLUDES *.o -lm $LIB_FUZZING_ENGINE -o $OUT/$target +done diff --git a/projects/libfdk-aac/project.yaml b/projects/libfdk-aac/project.yaml new file mode 100644 index 000000000..cd0affb88 --- /dev/null +++ b/projects/libfdk-aac/project.yaml @@ -0,0 +1,4 @@ +homepage: https://android.googlesource.com/platform/external/aac/ +primary_contact: audio-fdk@iis.fraunhofer.de +auto_ccs: + - "jmtrivi@google.com"