Coverage Report

Created: 2026-10-08 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/kcodecs/autotests/ossfuzz/kcodecs_fuzzer.cc
Line
Count
Source
1
/*
2
#
3
# SPDX-FileCopyrightText: 2019 Google Inc.
4
# SPDX-License-Identifier: Apache-2.0
5
#
6
# Copyright 2019 Google Inc.
7
#
8
# Licensed under the Apache License, Version 2.0 (the "License");
9
# you may not use this file except in compliance with the License.
10
# You may obtain a copy of the License at
11
#
12
#      http://www.apache.org/licenses/LICENSE-2.0
13
#
14
# Unless required by applicable law or agreed to in writing, software
15
# distributed under the License is distributed on an "AS IS" BASIS,
16
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
# See the License for the specific language governing permissions and
18
# limitations under the License.
19
#
20
################################################################################
21
*/
22
23
/*
24
  Usage:
25
    python infra/helper.py build_image kcodecs
26
    python infra/helper.py build_fuzzers --sanitizer undefined|address|memory kcodecs
27
    python infra/helper.py run_fuzzer kcodecs kcodecs_fuzzer
28
*/
29
30
#include <QCoreApplication>
31
#include <QVector>
32
33
#include <kcodecs.h>
34
#include <kencodingprober.h>
35
36
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
37
2.03k
{
38
2.03k
    int argc = 0;
39
2.03k
    QCoreApplication a(argc, nullptr);
40
41
2.03k
    const QByteArray ba((const char *)data, size);
42
2.03k
    const std::unique_ptr<KEncodingProber> prober = std::make_unique<KEncodingProber>();
43
44
    // Arabic, Baltic, CentralEuropean, Cyrillic, Greek, Hebrew, NorthernSaami, Other,
45
    // SouthEasternEurope, Thai, Turkish, WesternEuropean
46
    // All of these use nsSBCSGroupProber, so add only Arabic to avoid duplication
47
    // ChineseSimplified and ChineseTraditional both use ChineseGroupProber
48
2.03k
    const QVector<KEncodingProber::ProberType> allProbers = {
49
2.03k
        KEncodingProber::None,
50
2.03k
        KEncodingProber::Universal,
51
2.03k
        KEncodingProber::Arabic,
52
2.03k
        KEncodingProber::ChineseTraditional,
53
2.03k
        KEncodingProber::Japanese,
54
2.03k
        KEncodingProber::Korean,
55
2.03k
        KEncodingProber::Unicode
56
2.03k
    };
57
14.2k
    for (KEncodingProber::ProberType type : allProbers) {
58
14.2k
        prober->setProberType(type);
59
14.2k
        prober->feed(ba);
60
14.2k
        prober->reset();
61
14.2k
    }
62
63
2.03k
    const QVector<const char *> codecs = {"base64", "quoted-printable", "b", "q", "x-kmime-rfc2231", "x-uuencode"};
64
12.1k
    for (const char *codecName : codecs) {
65
12.1k
        KCodecs::Codec *c = KCodecs::Codec::codecForName(codecName);
66
12.1k
        c->encode(ba, KCodecs::Codec::NewlineCRLF);
67
12.1k
        c->decode(ba, KCodecs::Codec::NewlineCRLF);
68
12.1k
        c->encode(ba, KCodecs::Codec::NewlineLF);
69
12.1k
        c->decode(ba, KCodecs::Codec::NewlineLF);
70
12.1k
    }
71
72
2.03k
    return 0;
73
2.03k
}