diff --git a/targets/README.md b/targets/README.md index b5d2ee5c9..a228a6cc8 100644 --- a/targets/README.md +++ b/targets/README.md @@ -7,6 +7,7 @@ Targets integrated with oss-fuzz. | [boringssl](https://boringssl.googlesource.com/boringssl/) | [/targets/boringssl](boringssl) | | [curl](https://curl.haxx.se/) | [/targets/curl](curl) | | [expat](http://expat.sourceforge.net/) | [/targets/expat](expat) | +| [file (aka libmagic)](http://www.darwinsys.com/file/) | [/targets/file](file) | | [freetype2](https://www.freetype.org/) | [/targets/freetype2](freetype2) | | [harfbuzz](http://www.harfbuzz.org/) | [/targets/harfbuzz](harfbuzz) | | [icu](http://site.icu-project.org/) | [/targets/icu](icu) | diff --git a/targets/file/Dockerfile b/targets/file/Dockerfile new file mode 100644 index 000000000..0f05edc20 --- /dev/null +++ b/targets/file/Dockerfile @@ -0,0 +1,21 @@ +# Copyright 2016 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 ossfuzz/base-libfuzzer +MAINTAINER your@email.com +RUN apt-get install -y make autoconf automake libtool shtool +RUN git clone https://github.com/file/file.git +COPY build.sh magic_fuzzer.cc /src/ diff --git a/targets/file/Jenkinsfile b/targets/file/Jenkinsfile new file mode 100644 index 000000000..79ac9106c --- /dev/null +++ b/targets/file/Jenkinsfile @@ -0,0 +1,22 @@ +// Copyright 2016 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. +// +//////////////////////////////////////////////////////////////////////////////// + +def libfuzzerBuild = fileLoader.fromGit('infra/libfuzzer-pipeline.groovy', + 'https://github.com/google/oss-fuzz.git') + +libfuzzerBuild { + git = "https://github.com/file/file.git" +} diff --git a/targets/file/build.sh b/targets/file/build.sh new file mode 100755 index 000000000..64a1710bb --- /dev/null +++ b/targets/file/build.sh @@ -0,0 +1,26 @@ +#!/bin/bash -eu +# Copyright 2016 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. +# +################################################################################ + +cd /src/file + +autoreconf -i +./configure --enable-static +make V=1 all + +$CXX $CXXFLAGS -std=c++11 -Isrc/ \ + /src/magic_fuzzer.cc -o /out/magic_fuzzer \ + -lfuzzer ./src/.libs/libmagic.a $FUZZER_LDFLAGS diff --git a/targets/file/magic_fuzzer.cc b/targets/file/magic_fuzzer.cc new file mode 100644 index 000000000..713ffbe2a --- /dev/null +++ b/targets/file/magic_fuzzer.cc @@ -0,0 +1,28 @@ +// Copyright 2016 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 +#include + +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + if (size < 1) + return 0; + + magic_t magic = magic_open(MAGIC_NONE); + magic_buffer(magic, data, size); + magic_close(magic); + return 0; +}