-
Notifications
You must be signed in to change notification settings - Fork 576
Fix ArgumentOutOfRangeException for extreme datetime #5347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | |||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -236,5 +236,35 @@ | ||||||||||||||||||||||||||||||||||
| Assert.Fail($"A non-expected '{e.GetType()}' was raised. Url: {Client.HttpClient.BaseAddress}. No Activity Id present. Error: {e.Message}"); | |||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||
| [Theory] | |||||||||||||||||||||||||||||||||||
| [InlineData("ap9500-01-01")] // Approximate search with future date that causes overflow | |||||||||||||||||||||||||||||||||||
| [InlineData("ap0001-01-01")] // Approximate search with very old date | |||||||||||||||||||||||||||||||||||
| [InlineData("ap9999-12-31")] // Approximate search near max date | |||||||||||||||||||||||||||||||||||
| public async Task GivenAnApproximateDateSearchParamWithExtremeDate_WhenSearched_ThenServerShouldNotCrash(string queryValue) | |||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||
| try | |||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||
| // The server should handle extreme dates gracefully and return a successful response | |||||||||||||||||||||||||||||||||||
| // even if no results are found (empty bundle is OK) | |||||||||||||||||||||||||||||||||||
| Bundle bundle = await Client.SearchAsync(ResourceType.Patient, $"birthdate={queryValue}"); | |||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||
| // If we get here, the server handled it correctly - either with results or an empty bundle | |||||||||||||||||||||||||||||||||||
| Assert.NotNull(bundle); | |||||||||||||||||||||||||||||||||||
| Assert.Equal(Bundle.BundleType.Searchset, bundle.Type); | |||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||
| catch (FhirClientException fce) | |||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||
| // The server should NOT return 500 Internal Server Error for valid approximate date searches | |||||||||||||||||||||||||||||||||||
| // It's acceptable to return BadRequest if the server decides the date is out of reasonable bounds | |||||||||||||||||||||||||||||||||||
| Assert.True( | |||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this test should have two valid scenarios, it should either expect success or a bad request. |
|||||||||||||||||||||||||||||||||||
| fce.StatusCode != HttpStatusCode.InternalServerError, | |||||||||||||||||||||||||||||||||||
| $"Server returned '{HttpStatusCode.InternalServerError}' for a valid approximate date search. This indicates an unhandled exception (overflow) in the date calculation logic. Url: {Client.HttpClient.BaseAddress}. Activity Id: {fce.Response.GetRequestId()}. Error: {fce.Message}"); | |||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||
| catch (Exception e) | |||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||
| Assert.Fail($"An unexpected '{e.GetType()}' was raised. The server should handle extreme approximate dates gracefully. Url: {Client.HttpClient.BaseAddress}. Error: {e.Message}"); | |||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||
|
Comment on lines
+264
to
+267
Check noticeCode scanning / CodeQL Generic catch clause Note test
Generic catch clause.
Copilot AutofixAI about 1 month ago General approach: Replace the generic Best concrete fix here: Remove the Specifically, in
Suggested changeset
1
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/Search/DateSearchTests.cs
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
|||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused how this could ever overflow. nowTicks is approximately known to be 6.37e17 and maxTicks can't be greater than roughly 1/3 long.maxValue or less than 0, so their difference can't be outside the range of long (~9.22e18). ApproximateMultiplier is less than one so differenceTicks is less than rawDifference.
Is there something about this calculation I'm missing?