-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix CborWriter.Reset. #121188
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
Fix CborWriter.Reset. #121188
Conversation
The first issue is that Reset did not correctly set _definiteLength back after a reset. If allowMultipleRootLevelValues from the constructor is false, the default, it should be initialized to 1. However Reset set it as null, which behaves as if allowMultipleRootLevelValues is true. This sets _definiteLength back to the same way the constructor does. The second is that _currentIndefiniteLengthStringRanges is not cleared during Reset. This means if a Reset occurred while in the middle of writing an indefinite length value and convertIndefiniteLengthEncodings is true, the next time an encode tried to re-encode segments as definite encoding where the list indicated would be pointing to incorrect locations.
|
Tagging subscribers to this area: @dotnet/area-system-formats-cbor, @bartonjs, @vcsjones |
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.
Pull Request Overview
This PR fixes a bug in the CborWriter.Reset() method where two important writer state fields were not being properly reset. The fix ensures that after calling Reset(), the writer behaves correctly for both multiple root level value restrictions and indefinite-length string encoding conversions.
Key changes:
- Fixed
_definiteLengthto properly restore the initial state based onAllowMultipleRootLevelValuessetting - Added clearing of
_currentIndefiniteLengthStringRangesto prevent stale data from affecting subsequent writes - Added two test cases to verify the reset behavior
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Formats.Cbor/src/System/Formats/Cbor/Writer/CborWriter.cs | Fixed Reset() to properly restore _definiteLength based on writer configuration and clear indefinite-length string tracking data |
| src/libraries/System.Formats.Cbor/tests/Writer/CborWriterTests.cs | Added test coverage for Reset() preserving multiple root level restrictions and clearing indefinite-length string ranges |
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.
Thanks
|
/ba-g Android and Windows NAOT pipelines are timing out, but other pipelines validate the behavior. |
The first issue is that Reset did not correctly set _definiteLength back after a reset. If allowMultipleRootLevelValues from the constructor is false, the default, it should be initialized to 1. However Reset set it as null, which behaves as if allowMultipleRootLevelValues is true. This sets _definiteLength back to the same way the constructor does.
The second is that _currentIndefiniteLengthStringRanges is not cleared during Reset. This means if a Reset occurred while in the middle of writing an indefinite length value and convertIndefiniteLengthEncodings is true, the next time an encode tried to re-encode segments as definite encoding where the list indicated would be pointing to incorrect locations.
Fixes #121183
Fixes #121182