diff options
author | tsdgeos <aacid@kde.org> | 2019-02-06 00:45:03 +0100 |
---|---|---|
committer | Max Moroz <dor3s1@gmail.com> | 2019-02-05 15:45:03 -0800 |
commit | 25afe67574045dfab54c7550f38033bacf5af213 (patch) | |
tree | b3095f3e696dd9eaec7017d654ff4b83e8b3137b /projects/kcodecs | |
parent | 06321628901579b76f45a0948877bff6c64b2b5f (diff) | |
download | oss-fuzz-25afe67574045dfab54c7550f38033bacf5af213.tar.gz |
[kcodecs] Add new project: kcodecs (#2127)
Diffstat (limited to 'projects/kcodecs')
-rw-r--r-- | projects/kcodecs/Dockerfile | 26 | ||||
-rw-r--r-- | projects/kcodecs/build.sh | 46 | ||||
-rw-r--r-- | projects/kcodecs/kcodecs_fuzzer.cc | 83 | ||||
-rw-r--r-- | projects/kcodecs/project.yaml | 6 |
4 files changed, 161 insertions, 0 deletions
diff --git a/projects/kcodecs/Dockerfile b/projects/kcodecs/Dockerfile new file mode 100644 index 000000000..e9746998e --- /dev/null +++ b/projects/kcodecs/Dockerfile @@ -0,0 +1,26 @@ +# 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 tsdgeos@gmail.com +RUN apt-get install --yes cmake gperf +RUN git clone --depth 1 git://code.qt.io/qt/qtbase.git +RUN git clone --depth 1 git://anongit.kde.org/kcodecs +RUN git clone --depth 1 git://anongit.kde.org/extra-cmake-modules +RUN git clone --depth 1 https://gitlab.freedesktop.org/uchardet/uchardet.git +COPY build.sh $SRC +COPY kcodecs_fuzzer.cc $SRC +WORKDIR kcodecs diff --git a/projects/kcodecs/build.sh b/projects/kcodecs/build.sh new file mode 100644 index 000000000..c11003791 --- /dev/null +++ b/projects/kcodecs/build.sh @@ -0,0 +1,46 @@ +#!/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. +# +################################################################################ + +cd $SRC +cd extra-cmake-modules +cmake . +make install + +cd $SRC +cd qtbase +# add the flags to Qt build too, we may as well sanitize Qt too (and also fixes memory sanitizer build) +sed -i -e "s/QMAKE_CXXFLAGS += -stdlib=libc++/QMAKE_CXXFLAGS += -stdlib=libc++ $CXXFLAGS/g" mkspecs/linux-clang-libc++/qmake.conf +sed -i -e "s/QMAKE_LFLAGS += -stdlib=libc++/QMAKE_LFLAGS += -stdlib=libc++ -lpthread $CXXFLAGS/g" mkspecs/linux-clang-libc++/qmake.conf +# Disable compressing rcc files, triggers a warning in the memory sanitizer that i'm not sure is valid. TODO investigate properly +sed -i -e "s/DEFINES += QT_RCC QT_NO_CAST_FROM_ASCII QT_NO_FOREACH/DEFINES += QT_NO_COMPRESS QT_RCC QT_NO_CAST_FROM_ASCII QT_NO_FOREACH/g" src/tools/rcc/rcc.pro +./configure --glib=no --libpng=qt -opensource -confirm-license -static -no-opengl -no-icu -platform linux-clang-libc++ -v +cd src +../bin/qmake -o Makefile src.pro +make sub-corelib -j$(nproc) + +cd $SRC +cd kcodecs +cmake . -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$SRC/qtbase +make -j$(nproc) VERBOSE=1 + + +$CXX $CXXFLAGS -fPIC -std=c++11 $SRC/kcodecs_fuzzer.cc -o $OUT/kcodecs_fuzzer \ + -I $SRC/qtbase/include/QtCore/ -I $SRC/qtbase/include/ -I $SRC/kcodecs/src \ + -I $SRC/kcodecs/src/probers -L $SRC/qtbase/lib -L $SRC/kcodecs/lib \ + -lQt5Core -lm -lqtpcre2 -ldl -lpthread -lFuzzingEngine -lKF5Codecs + +zip -qr $OUT/kcodecs_fuzzer_seed_corpus.zip $SRC/uchardet/test/ $SRC/kcodecs/autotests/data diff --git a/projects/kcodecs/kcodecs_fuzzer.cc b/projects/kcodecs/kcodecs_fuzzer.cc new file mode 100644 index 000000000..76ec8f2ee --- /dev/null +++ b/projects/kcodecs/kcodecs_fuzzer.cc @@ -0,0 +1,83 @@ +/* +# 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. +# +################################################################################ +*/ + +/* + Usage: + python infra/helper.py build_image kcodecs + python infra/helper.py build_fuzzers --sanitizer undefined|address|memory kcodecs + python infra/helper.py run_fuzzer kcodecs kcodecs_fuzzer +*/ + + +#include <QCoreApplication> +#include <QVector> + +#include "JapaneseGroupProber.h" +#include "nsBig5Prober.h" +#include "nsEUCJPProber.h" +#include "nsGB2312Prober.h" +#include "nsLatin1Prober.h" +#include "nsSBCSGroupProber.h" +#include "nsUniversalDetector.h" +#include "ChineseGroupProber.h" +#include "nsEscCharsetProber.h" +#include "nsEUCKRProber.h" +#include "nsMBCSGroupProber.h" +#include "nsSJISProber.h" +#include "UnicodeGroupProber.h" +#include "kcodecs.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + int argc = 0; + QCoreApplication a(argc, nullptr); + + const QVector<kencodingprober::nsCharSetProber*> probers = { + new kencodingprober::JapaneseGroupProber(), + new kencodingprober::nsBig5Prober(), + new kencodingprober::nsEUCJPProber(), + new kencodingprober::nsGB18030Prober(), + new kencodingprober::nsLatin1Prober(), + new kencodingprober::nsSBCSGroupProber(), + new kencodingprober::nsUniversalDetector(), + new kencodingprober::ChineseGroupProber(), + new kencodingprober::nsEscCharSetProber(), + new kencodingprober::nsEUCKRProber(), + new kencodingprober::nsMBCSGroupProber(), + new kencodingprober::nsSJISProber(), + new kencodingprober::UnicodeGroupProber() + }; + + for (kencodingprober::nsCharSetProber *p : probers) { + p->HandleData((const char*)data, size); + } + + qDeleteAll(probers); + + const QByteArray ba((const char *)data, size); + const QVector<const char*> codecs = { "base64", "quoted-printable", "b", "q", "x-kmime-rfc2231", "x-uuencode" }; + for (const char *codecName : codecs) { + KCodecs::Codec *c = KCodecs::Codec::codecForName(codecName); + c->encode(ba, KCodecs::Codec::NewlineCRLF); + c->decode(ba, KCodecs::Codec::NewlineCRLF); + c->encode(ba, KCodecs::Codec::NewlineLF); + c->decode(ba, KCodecs::Codec::NewlineLF); + } + + return 0; +} diff --git a/projects/kcodecs/project.yaml b/projects/kcodecs/project.yaml new file mode 100644 index 000000000..e6f8472b1 --- /dev/null +++ b/projects/kcodecs/project.yaml @@ -0,0 +1,6 @@ +homepage: https://cgit.kde.org/kcodecs.git/ +primary_contact: tsdgeos@gmail.com +sanitizers: + - address + - memory + - undefined |