Coverage Report

Created: 2026-01-25 06:58

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
7.99k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
14
7.99k
    uint16_t rnd;
15
7.99k
    icu::DateFormatSymbols::DtContextType context;
16
7.99k
    icu::DateFormatSymbols::DtWidthType width;
17
7.99k
    if (size < sizeof(rnd) + sizeof(context) + sizeof(width)) return 0;
18
7.98k
    icu::StringPiece fuzzData(reinterpret_cast<const char *>(data), size);
19
20
7.98k
    std::memcpy(&rnd, fuzzData.data(), sizeof(rnd));
21
7.98k
    icu::Locale locale = GetRandomLocale(rnd);
22
7.98k
    fuzzData.remove_prefix(sizeof(rnd));
23
24
7.98k
    std::memcpy(&context, fuzzData.data(), sizeof(context));
25
7.98k
    fuzzData.remove_prefix(sizeof(context));
26
7.98k
    icu::DateFormatSymbols::DtContextType context_mod =
27
7.98k
        static_cast<icu::DateFormatSymbols::DtContextType>(
28
7.98k
            context % icu::DateFormatSymbols::DtContextType::DT_CONTEXT_COUNT);
29
7.98k
;
30
7.98k
    std::memcpy(&width, fuzzData.data(), sizeof(width));
31
7.98k
    fuzzData.remove_prefix(sizeof(width));
32
7.98k
    icu::DateFormatSymbols::DtWidthType width_mod =
33
7.98k
        static_cast<icu::DateFormatSymbols::DtWidthType>(
34
7.98k
            width % icu::DateFormatSymbols::DtWidthType::DT_WIDTH_COUNT);
35
36
7.98k
    size_t len = fuzzData.size() / sizeof(char16_t);
37
7.98k
    icu::UnicodeString text(false, reinterpret_cast<const char16_t*>(fuzzData.data()), len);
38
7.98k
    const icu::UnicodeString items[] = { text, text, text, text };
39
40
7.98k
    UErrorCode status = U_ZERO_ERROR;
41
7.98k
    std::unique_ptr<icu::DateFormatSymbols> dfs(
42
7.98k
        new icu::DateFormatSymbols(locale, status));
43
7.98k
    if (U_FAILURE(status)) {
44
0
        return EXIT_SUCCESS;
45
0
    }
46
47
7.98k
    int32_t count;
48
7.98k
    dfs->getEras(count);
49
7.98k
    dfs->getEraNames(count);
50
7.98k
    dfs->getNarrowEras(count);
51
7.98k
    dfs->getMonths(count);
52
7.98k
    dfs->getShortMonths(count);
53
7.98k
    dfs->getMonths(count, context, width);
54
7.98k
    dfs->getMonths(count, context_mod, width_mod);
55
7.98k
    dfs->getWeekdays(count);
56
7.98k
    dfs->getShortWeekdays(count);
57
7.98k
    dfs->getWeekdays(count, context, width);
58
7.98k
    dfs->getWeekdays(count, context_mod, width_mod);
59
7.98k
    dfs->getShortWeekdays(count);
60
7.98k
    dfs->getQuarters(count, context_mod, width_mod);
61
7.98k
    dfs->getAmPmStrings(count);
62
63
7.98k
    icu::UnicodeString output;
64
7.98k
    dfs->getTimeSeparatorString(output);
65
7.98k
    dfs->getYearNames(count, context, width);
66
7.98k
    dfs->getYearNames(count, context_mod, width_mod);
67
7.98k
    dfs->getZodiacNames(count, context, width);
68
7.98k
    dfs->getZodiacNames(count, context_mod, width_mod);
69
7.98k
    dfs->getLeapMonthPatterns(count);
70
7.98k
    int32_t count2;
71
7.98k
    dfs->getZoneStrings(count, count2);
72
7.98k
    dfs->getLocalPatternChars(output);
73
74
    return EXIT_SUCCESS;
75
7.98k
}