Coverage Report

Created: 2026-03-31 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/icu/icu4c/source/test/fuzzer/dtfmtsym_fuzzer.cpp
Line
Count
Source
1
// © 2023 and later: Unicode, Inc. and others.
2
// License & terms of use: http://www.unicode.org/copyright.html
3
4
// Fuzzer for ICU DateFormatSymbols.
5
6
#include <cstring>
7
8
#include "fuzzer_utils.h"
9
10
#include "unicode/dtfmtsym.h"
11
#include "unicode/locid.h"
12
13
8.42k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
14
8.42k
    uint16_t rnd;
15
8.42k
    icu::DateFormatSymbols::DtContextType context;
16
8.42k
    icu::DateFormatSymbols::DtWidthType width;
17
8.42k
    if (size < sizeof(rnd) + sizeof(context) + sizeof(width)) return 0;
18
8.41k
    icu::StringPiece fuzzData(reinterpret_cast<const char *>(data), size);
19
20
8.41k
    std::memcpy(&rnd, fuzzData.data(), sizeof(rnd));
21
8.41k
    icu::Locale locale = GetRandomLocale(rnd);
22
8.41k
    fuzzData.remove_prefix(sizeof(rnd));
23
24
8.41k
    std::memcpy(&context, fuzzData.data(), sizeof(context));
25
8.41k
    fuzzData.remove_prefix(sizeof(context));
26
8.41k
    icu::DateFormatSymbols::DtContextType context_mod =
27
8.41k
        static_cast<icu::DateFormatSymbols::DtContextType>(
28
8.41k
            context % icu::DateFormatSymbols::DtContextType::DT_CONTEXT_COUNT);
29
8.41k
;
30
8.41k
    std::memcpy(&width, fuzzData.data(), sizeof(width));
31
8.41k
    fuzzData.remove_prefix(sizeof(width));
32
8.41k
    icu::DateFormatSymbols::DtWidthType width_mod =
33
8.41k
        static_cast<icu::DateFormatSymbols::DtWidthType>(
34
8.41k
            width % icu::DateFormatSymbols::DtWidthType::DT_WIDTH_COUNT);
35
36
8.41k
    size_t len = fuzzData.size() / sizeof(char16_t);
37
8.41k
    icu::UnicodeString text(false, reinterpret_cast<const char16_t*>(fuzzData.data()), len);
38
8.41k
    const icu::UnicodeString items[] = { text, text, text, text };
39
40
8.41k
    UErrorCode status = U_ZERO_ERROR;
41
8.41k
    std::unique_ptr<icu::DateFormatSymbols> dfs(
42
8.41k
        new icu::DateFormatSymbols(locale, status));
43
8.41k
    if (U_FAILURE(status)) {
44
0
        return EXIT_SUCCESS;
45
0
    }
46
47
8.41k
    int32_t count;
48
8.41k
    dfs->getEras(count);
49
8.41k
    dfs->getEraNames(count);
50
8.41k
    dfs->getNarrowEras(count);
51
8.41k
    dfs->getMonths(count);
52
8.41k
    dfs->getShortMonths(count);
53
8.41k
    dfs->getMonths(count, context, width);
54
8.41k
    dfs->getMonths(count, context_mod, width_mod);
55
8.41k
    dfs->getWeekdays(count);
56
8.41k
    dfs->getShortWeekdays(count);
57
8.41k
    dfs->getWeekdays(count, context, width);
58
8.41k
    dfs->getWeekdays(count, context_mod, width_mod);
59
8.41k
    dfs->getShortWeekdays(count);
60
8.41k
    dfs->getQuarters(count, context_mod, width_mod);
61
8.41k
    dfs->getAmPmStrings(count);
62
63
8.41k
    icu::UnicodeString output;
64
8.41k
    dfs->getTimeSeparatorString(output);
65
8.41k
    dfs->getYearNames(count, context, width);
66
8.41k
    dfs->getYearNames(count, context_mod, width_mod);
67
8.41k
    dfs->getZodiacNames(count, context, width);
68
8.41k
    dfs->getZodiacNames(count, context_mod, width_mod);
69
8.41k
    dfs->getLeapMonthPatterns(count);
70
8.41k
    int32_t count2;
71
8.41k
    dfs->getZoneStrings(count, count2);
72
8.41k
    dfs->getLocalPatternChars(output);
73
74
    return EXIT_SUCCESS;
75
8.41k
}