ICU-23336 Fix undefined behavior in dtfmtsym_fuzzer: validate enum values#3889
Open
OwenSanzas wants to merge 1 commit intounicode-org:mainfrom
Open
ICU-23336 Fix undefined behavior in dtfmtsym_fuzzer: validate enum values#3889OwenSanzas wants to merge 1 commit intounicode-org:mainfrom
OwenSanzas wants to merge 1 commit intounicode-org:mainfrom
Conversation
…fuzz data The harness reads DtContextType and DtWidthType directly from fuzz data via memcpy into enum variables without validation. These arbitrary values are undefined behavior when loaded as C++ enum types, confirmed by UndefinedBehaviorSanitizer: runtime error: load of value 3735928559, which is not a valid value for type 'icu::DateFormatSymbols::DtContextType' The fix reads into int32_t first, then clamps to valid enum ranges using modulo before casting to the enum type. Also removes duplicate API calls that used the raw unvalidated values alongside validated _mod versions.
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
The
dtfmtsym_fuzzerharness readsDtContextTypeandDtWidthTypedirectly from fuzz data viamemcpyinto enum variables without validation. Loading arbitrary bit patterns into C++ enum types is undefined behavior.Confirmed with UndefinedBehaviorSanitizer:
The harness already partially addressed this by creating
context_modandwidth_modvalidated versions, but it also passed the raw unvalidatedcontextandwidthtogetMonths(),getWeekdays(),getYearNames(), andgetZodiacNames().Changes
int32_tinstead of directly into enum types (eliminates UB at thememcpypoint)_modversionsExperimental Verification (60-second fuzzing, AddressSanitizer)
Coverage is equivalent — the fix eliminates the UB without affecting fuzzing effectiveness.
UBSan Evidence
context=0xDEADBEEF, width=0xDEADBEEF