Skip to content

[Json] Fix error case in HalfConverter when dealing with large values #116884

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

Merged
merged 2 commits into from
Jul 2, 2025

Conversation

BrennanConroy
Copy link
Member

When deserializing Half, sending a large value like 123456789012345678901 would result in ArgumentException: Destination is too short.

@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 23:08
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an error encountered when deserializing large Half values by adjusting the buffer length validations and adding comprehensive tests for various numeric types.

  • Updated the HalfConverter to use a new constant for unescaped format length checks.
  • Added new theory tests in NumberHandlingTests to validate error handling for large values across multiple numeric types.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/libraries/System.Text.Json/tests/Common/NumberHandlingTests.cs Added tests to verify proper exception throwing for oversized values during deserialization.
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/HalfConverter.cs Modified the logic in TryGetFloatingPointConstant to properly check the value length for both escaped and unescaped constants.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

@BrennanConroy
Copy link
Member Author

/azp run

Copy link

You have several pipelines (over 10) configured to build pull requests in this repository. Specify which pipelines you would like to run by using /azp run [pipelines] command. You can specify multiple pipelines using a comma separated list.

@BrennanConroy
Copy link
Member Author

/azp run all

Copy link

No pipelines are associated with this pull request.

@BrennanConroy
Copy link
Member Author

/azp run runtime

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@BrennanConroy BrennanConroy merged commit 2548aa0 into dotnet:main Jul 2, 2025
82 of 86 checks passed
@BrennanConroy BrennanConroy deleted the brecon/half branch July 2, 2025 23:55
@github-actions github-actions bot locked and limited conversation to collaborators Aug 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants