Line | Count | Source |
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 | | |
45 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
46 | 1.93k | { |
47 | 1.93k | int argc = 0; |
48 | 1.93k | QCoreApplication a(argc, nullptr); |
49 | | |
50 | 1.93k | const QVector<kencodingprober::nsCharSetProber*> probers = { |
51 | 1.93k | new kencodingprober::JapaneseGroupProber(), |
52 | 1.93k | new kencodingprober::nsBig5Prober(), |
53 | 1.93k | new kencodingprober::nsEUCJPProber(), |
54 | 1.93k | new kencodingprober::nsGB18030Prober(), |
55 | 1.93k | new kencodingprober::nsLatin1Prober(), |
56 | 1.93k | new kencodingprober::nsSBCSGroupProber(), |
57 | 1.93k | new kencodingprober::nsUniversalDetector(), |
58 | 1.93k | new kencodingprober::ChineseGroupProber(), |
59 | 1.93k | new kencodingprober::nsEscCharSetProber(), |
60 | 1.93k | new kencodingprober::nsEUCKRProber(), |
61 | 1.93k | new kencodingprober::nsMBCSGroupProber(), |
62 | 1.93k | new kencodingprober::nsSJISProber(), |
63 | 1.93k | new kencodingprober::UnicodeGroupProber() |
64 | 1.93k | }; |
65 | | |
66 | 25.1k | for (kencodingprober::nsCharSetProber *p : probers) { |
67 | 25.1k | p->HandleData((const char*)data, size); |
68 | 25.1k | } |
69 | | |
70 | 1.93k | qDeleteAll(probers); |
71 | | |
72 | 1.93k | const QByteArray ba((const char *)data, size); |
73 | 1.93k | const QVector<const char*> codecs = { "base64", "quoted-printable", "b", "q", "x-kmime-rfc2231", "x-uuencode" }; |
74 | 11.5k | for (const char *codecName : codecs) { |
75 | 11.5k | KCodecs::Codec *c = KCodecs::Codec::codecForName(codecName); |
76 | 11.5k | c->encode(ba, KCodecs::Codec::NewlineCRLF); |
77 | 11.5k | c->decode(ba, KCodecs::Codec::NewlineCRLF); |
78 | 11.5k | c->encode(ba, KCodecs::Codec::NewlineLF); |
79 | 11.5k | c->decode(ba, KCodecs::Codec::NewlineLF); |
80 | 11.5k | } |
81 | | |
82 | 1.93k | return 0; |
83 | 1.93k | } |