Skip to content
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

[release/5.0-rc2] Prevent JSON async deserialization errors when partial buffer ends in the middle of null token (#42158) #42359

Merged
merged 1 commit into from
Sep 18, 2020

Conversation

layomia
Copy link
Contributor

@layomia layomia commented Sep 17, 2020

Backport of #42158 ("Fix continuation of JSON deserialization") to release/5.0-rc2. Updated this PR's title to more accurately reflect the issue being fixed.

Customer Impact

Prior to this PR, the serializer could throw a JSON exception when async deserializing JSON payloads that contain null tokens. If a partial segment of the payload being read ended in the middle of a null token, the serializer could throw a JsonException after fetching more data and resuming deserialization.

A simple example:

Initial buffer: {"Foo":"Bar","Baz":nu

Next buffer: ll,"Qux":"Quux"} // Serializer throws error when resuming deserializing after fetching this data.


async and null handling are both commonly used features in the serializer. This issue would likely be faced by numerous users if not fixed.

Testing

The PR has been tested extensively across multiple factors: null token position, matching property type (nullable/non-nullable), deserialization constructor mode (parameterized/non-parameterized), payload size (small/large), and so on.

The fixing PR has also been verified on customer input which flagged down the issue.

Risk

This fix is small and targeted. It is unlikely to cause issues elsewhere.

* Repro dotnet#42070

* formatting

* namespace

* Fix

* never forget the header

* More tests
- Test continuation at every position inside the tested object
- Many member with primitive and nullable types
- One more level of nested object
- All combinations of class/struct for tested and nested object
- tested and nested object with parametrized ctor for some properties

* Addressed feedback

* Test with original repro data from dotnet#42070

* custom converter to ensure the padding is written in front of the tested object

* rename

* test data moved to Strings.resx
@layomia layomia added Servicing-consider Issue for next servicing release review area-System.Text.Json labels Sep 17, 2020
@layomia layomia added this to the 5.0.0 milestone Sep 17, 2020
@layomia layomia self-assigned this Sep 17, 2020
@danmoseley
Copy link
Member

Great info in template. However if this is a bad regression why did we only know about it now at the last minute? Or did it regress recently?

@layomia
Copy link
Contributor Author

layomia commented Sep 17, 2020

I think more people are trying out System.Text.Json in .NET 5 due to RC1 release, especially as JSON improvements were highlighted in the blog post. The plan is to bolster the tests for more continuation scenarios - #42158 (comment) and continue testing/validating other features.

@danmoseley
Copy link
Member

danmoseley commented Sep 17, 2020

Thanks. It would be good to include that extended testing in this PR, if it’s for related issues. The goal is to minimize the possibility we have to bring another. We can take to tactics tomorrow even if that part is not ready, but that way if something else is found we can potentially roll it in before we merge it.

Copy link
Member

@steveharter steveharter left a comment

Choose a reason for hiding this comment

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

LGTM; definitely agree that we need this in 5.0.

@layomia layomia removed the Servicing-consider Issue for next servicing release review label Sep 17, 2020
@layomia
Copy link
Contributor Author

layomia commented Sep 17, 2020

Okay to wait until the extended testing is in - #42393.

@danmoseley
Copy link
Member

@ericstj I’m supportive, feel free to send mail to tactics if you support it

@danmoseley
Copy link
Member

danmoseley commented Sep 17, 2020

Don't let it stop this PR, but I think these test strings of > 200KB probably should be in the test data repo as they just bloat the repo. Once you've merged them though, that bloat is locked in so it's more of a future suggestion.

@ericstj ericstj added the Servicing-approved Approved for servicing release label Sep 18, 2020
@ericstj
Copy link
Member

ericstj commented Sep 18, 2020

approved over mail. Merge at will.

You can address the string suggestion in master. @danmosemsft we're usually more sensitive about the type of data and how much it changes. Text data is typically OK at somewhat larger sizes if it doesn't change too often, since it compresses really well in git. In fact git uses zlib compression which is based on DEFLATE same as zip used in nupkg. Binary data, especially binary data that changes often, is what we make sure to put in assets packages. Also any large data that would be considered "optional" for some repo consumers. Maybe we could write some guidelines down somewhere :)

@danmoseley
Copy link
Member

@ericstj that makes sense. sounds good

@layomia
Copy link
Contributor Author

layomia commented Sep 18, 2020

You can address the string suggestion in master.

Maybe we could write some guidelines down somewhere :)

Opened #42428 to track these.

@layomia layomia merged commit 4e46471 into dotnet:release/5.0-rc2 Sep 18, 2020
@layomia layomia deleted the null_continuation_net5 branch September 18, 2020 03:05
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants