ICU-23335 Fix undefined behavior and null-deref in date_format_fuzzer#3888
Open
OwenSanzas wants to merge 1 commit intounicode-org:mainfrom
Open
ICU-23335 Fix undefined behavior and null-deref in date_format_fuzzer#3888OwenSanzas wants to merge 1 commit intounicode-org:mainfrom
OwenSanzas wants to merge 1 commit intounicode-org:mainfrom
Conversation
Two issues in the date_format_fuzzer fuzz harness: 1. dateStyle and timeStyle are read from fuzz data via memcpy directly into EStyle enum variables without validation. The EStyle enum has only 13 valid values, so arbitrary 32-bit values are undefined behavior. UBSan confirms: "load of value -559038737, which is not a valid value for type 'icu::DateFormat::EStyle'". Fix: use styles[rnd2 % numStyles] for all style variables, consistent with how dateStyle2/timeStyle2 are already handled. 2. df->format() is called without checking if df is nullptr. While createDateTimeInstance rarely returns nullptr in practice, the missing null checks are inconsistent with the later createInstanceForSkeleton calls which do check. Fix: add null checks before all df->format() calls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix two issues in
icu4c/source/test/fuzzer/date_format_fuzzer.cpp:1. Undefined behavior: invalid enum values
dateStyleandtimeStyleare read from fuzz data viamemcpydirectly intoEStyleenum variables without validation. TheEStyleenum has only 13 valid values, so arbitrary 32-bit values are undefined behavior per the C++ standard.Confirmed with UndefinedBehaviorSanitizer:
The harness already has the correct pattern for
dateStyle2/timeStyle2— they usestyles[rnd2 % numStyles]. The first pair was an oversight.Fix: Use
styles[rnd2 % numStyles]for all style variables, consistent with the existing pattern.2. Missing null checks before df->format()
df->format(date, appendTo)is called without checking ifdfis nullptr aftercreateDateTimeInstance. WhilecreateDateTimeInstancerarely returns nullptr in practice, the missing null checks are inconsistent with the latercreateInstanceForSkeletoncalls which do check for success.Fix: Add null checks (
if (df)) before alldf->format()calls.Before/After Comparison (60-second fuzzing, AddressSanitizer)
The fixed version achieves 13% more edge coverage because valid
EStyleenum values trigger moreDateFormatinternal code paths (e.g.,RelativeDateFormat, various style combinations) instead of always falling through to the default fallback path.Changes
dateStyle/timeStyleasuint8_t+ modulo index intostyles[](same asdateStyle2/timeStyle2)uint8_tinstead of 2 ×uint8_t+ 2 ×sizeof(EStyle))df->format()callsstatusbeforeudat_opencall