Repository navigation
Fix TimeSpan parsing of long fractional seconds - #137147
Merged
Merged
Conversation
Extend the integer power-of-ten table to cover the scaling exponents required by long fractions with leading zeroes. Preserve existing rounding and token overflow behavior, and add regression coverage for Parse and TryParse. Co-authored-by: Copilot App <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-datetime |
Member
tarekgh
reviewed
Nov 8, 2026
tarekgh
reviewed
Nov 8, 2026
Use uint.PowersOf10 directly and remove the TimeSpanParse helper. Add long-fraction G cases to the shared ParseExact test data. Co-authored-by: Copilot App <[email protected]>
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
Restore parsing of long fractional seconds with leading zeroes by extending the integer powers-of-ten table through
10^9. Reuse the shareduint.PowersOf10table directly instead of maintaining aTimeSpanParse-specific helper.Reproduction and rationale
According to the TIMESPAN-1 report, .NET 8 successfully parses the original input,
"0:0:0.0000000123456789", asTimeSpan.Zero:TryParsereturnstruerather than throwing. The same input throws on .NET 9 and 10, so this is a regression of previously accepted input, not just an unsupported format.The following behavior was reproduced locally on .NET 10.0.14:
The inconsistency comes from two normalization paths. With eight leading zeroes, the fraction is small enough to round to zero and returns early. With seven leading zeroes and nine significant digits, normalization divides the stored integer by
10^(16 - 7), but the existing table only contains10^0through10^7.The shared powers-of-ten table was previously limited to that range. The fuzz report identifies the resulting behavior as a regression from .NET 8 to .NET 9; that version comparison was not independently rerun here.
There are two reasons to fix this rather than reject all fractions longer than seven digits:
TryParsecontract returnsfalsefor an invalid time-interval format or an out-of-range value. This input should not cause an internal array-index exception to escape an ordinary parse attempt.The fix preserves the existing integer rounding and tokenizer overflow rules. It does not introduce arbitrary-length or higher-precision parsing.
ParseandTryParse, including their standard"g"and span paths, use the corrected normalization code. The follow-up test coverage also exercises long-fraction"g"parsing through the sharedParseExacttest data.Validation
Linux ARM64 Docker (Ubuntu 24.04, checked CoreCLR): builds passed, and the regression test fails on the unfixed code. After the fix, the TimeSpan and related date/time tests passed without failures.
Relates to #134839 (TIMESPAN-1 only).
Note
This pull request description was generated with GitHub Copilot.