1 /*
2 # Copyright 2019 Google Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 ################################################################################
17 */
18
19 /*
20 Usage:
21 python infra/helper.py build_image kcodecs
22 python infra/helper.py build_fuzzers --sanitizer undefined|address|memory kcodecs
23 python infra/helper.py run_fuzzer kcodecs kcodecs_fuzzer
24 */
25
26
27 #include <QCoreApplication>
28 #include <QVector>
29
30 #include "JapaneseGroupProber.h"
31 #include "nsBig5Prober.h"
32 #include "nsEUCJPProber.h"
33 #include "nsGB2312Prober.h"
34 #include "nsLatin1Prober.h"
35 #include "nsSBCSGroupProber.h"
36 #include "nsUniversalDetector.h"
37 #include "ChineseGroupProber.h"
38 #include "nsEscCharsetProber.h"
39 #include "nsEUCKRProber.h"
40 #include "nsMBCSGroupProber.h"
41 #include "nsSJISProber.h"
42 #include "UnicodeGroupProber.h"
43 #include "kcodecs.h"
44
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)45 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
46 {
47 int argc = 0;
48 QCoreApplication a(argc, nullptr);
49
50 const QVector<kencodingprober::nsCharSetProber*> probers = {
51 new kencodingprober::JapaneseGroupProber(),
52 new kencodingprober::nsBig5Prober(),
53 new kencodingprober::nsEUCJPProber(),
54 new kencodingprober::nsGB18030Prober(),
55 new kencodingprober::nsLatin1Prober(),
56 new kencodingprober::nsSBCSGroupProber(),
57 new kencodingprober::nsUniversalDetector(),
58 new kencodingprober::ChineseGroupProber(),
59 new kencodingprober::nsEscCharSetProber(),
60 new kencodingprober::nsEUCKRProber(),
61 new kencodingprober::nsMBCSGroupProber(),
62 new kencodingprober::nsSJISProber(),
63 new kencodingprober::UnicodeGroupProber()
64 };
65
66 for (kencodingprober::nsCharSetProber *p : probers) {
67 p->HandleData((const char*)data, size);
68 }
69
70 qDeleteAll(probers);
71
72 const QByteArray ba((const char *)data, size);
73 const QVector<const char*> codecs = { "base64", "quoted-printable", "b", "q", "x-kmime-rfc2231", "x-uuencode" };
74 for (const char *codecName : codecs) {
75 KCodecs::Codec *c = KCodecs::Codec::codecForName(codecName);
76 c->encode(ba, KCodecs::Codec::NewlineCRLF);
77 c->decode(ba, KCodecs::Codec::NewlineCRLF);
78 c->encode(ba, KCodecs::Codec::NewlineLF);
79 c->decode(ba, KCodecs::Codec::NewlineLF);
80 }
81
82 return 0;
83 }
84