Skip to content

Commit

Permalink
ICU-22549 Add TimeZoneNames fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankYFTang committed Dec 14, 2023
1 parent 4a7d61d commit cae9233
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions icu4c/source/i18n/tznames_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,11 +1303,16 @@ static void mergeTimeZoneKey(const UnicodeString& mzID, char* result) {
ZNames*
TimeZoneNamesImpl::loadMetaZoneNames(const UnicodeString& mzID, UErrorCode& status) {
if (U_FAILURE(status)) { return nullptr; }
U_ASSERT(mzID.length() <= ZID_KEY_MAX - MZ_PREFIX_LEN);
if (mzID.length() > ZID_KEY_MAX - MZ_PREFIX_LEN) {
status = U_INTERNAL_PROGRAM_ERROR;
return nullptr;
}

char16_t mzIDKey[ZID_KEY_MAX + 1];
mzID.extract(mzIDKey, ZID_KEY_MAX + 1, status);
U_ASSERT(U_SUCCESS(status)); // already checked length above
if (U_FAILURE(status)) {
return nullptr;
}
mzIDKey[mzID.length()] = 0;

void* mznames = uhash_get(fMZNamesMap, mzIDKey);
Expand All @@ -1331,7 +1336,10 @@ TimeZoneNamesImpl::loadMetaZoneNames(const UnicodeString& mzID, UErrorCode& stat
ZNames*
TimeZoneNamesImpl::loadTimeZoneNames(const UnicodeString& tzID, UErrorCode& status) {
if (U_FAILURE(status)) { return nullptr; }
U_ASSERT(tzID.length() <= ZID_KEY_MAX);
if (tzID.length() > ZID_KEY_MAX) {
status = U_INTERNAL_PROGRAM_ERROR;
return nullptr;
}

char16_t tzIDKey[ZID_KEY_MAX + 1];
int32_t tzIDKeyLen = tzID.extract(tzIDKey, ZID_KEY_MAX + 1, status);
Expand Down Expand Up @@ -2248,7 +2256,9 @@ TZDBTimeZoneNames::getMetaZoneNames(const UnicodeString& mzID, UErrorCode& statu

char16_t mzIDKey[ZID_KEY_MAX + 1];
mzID.extract(mzIDKey, ZID_KEY_MAX + 1, status);
U_ASSERT(status == U_ZERO_ERROR); // already checked length above
if (U_FAILURE(status)) {
return nullptr;
}
mzIDKey[mzID.length()] = 0;

static UMutex gTZDBNamesMapLock;
Expand Down
1 change: 1 addition & 0 deletions icu4c/source/test/fuzzer/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ FUZZER_TARGETS = \
relative_date_time_formatter_fuzzer \
rule_based_break_iterator_fuzzer \
timezone_create_fuzzer \
time_zone_names_fuzzer \
ucasemap_fuzzer \
uloc_canonicalize_fuzzer \
uloc_for_language_tag_fuzzer \
Expand Down

0 comments on commit cae9233

Please sign in to comment.