-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[System.Text.Json] UnsafeRelaxedJsonEscaping can result in StackOverflowException #30814
Comments
From @rynowak on Tuesday, September 10, 2019 2:51:25 PM @ahsonkhan - the only differnce between these cases appears to be the text. |
From @mkArtakMSFT on Tuesday, September 10, 2019 4:00:42 PM @rynowak I can repro this. yes, the only difference is the text. |
From @mkArtakMSFT on Tuesday, September 10, 2019 4:01:06 PM Thanks for reporting this, @Zonciu. |
From @mkArtakMSFT on Tuesday, September 10, 2019 4:04:23 PM
|
From @pranavkm on Tuesday, September 10, 2019 4:27:00 PM Here's the minimal repro step without MVC involved: var test = new { Name = "测试11" };
Console.WriteLine(JsonSerializer.Serialize(test, new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, PropertyNamingPolicy = JsonNamingPolicy.CamelCase })); Here's what's causing the StackOverflow: It's specifically the |
Let's try to get this in 3.0. @ahsonkhan can you take a look. |
@Zonciu, in the meanwhile, you could configure MVC to use the default JavaScriptEncoder which works around this particular instance of the issue: // Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers().AddJsonOptions(options => options.JsonSerializerOptions.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Default);
} |
@Zonciu, note, that particular workaround wouldn't work in general. I couldn't come up with a good workaround for the bug. Please re-try with the latest changes/nightly build and verify the issue has been fixed for your scenario. Otherwise, re-open the issue. Fixed in master by dotnet/corefx#40996, and in release by dotnet/corefx#40997 |
@ahsonkhan @pranavkm For now I use |
That works too. Let me know when you revert back to using the built-in serializer and if you find any bugs/issues or have some feedback to share. |
I have the same issue using |
@xcaptain It has been fixed in nightly build, but not in 3.0 rc1 |
I'm still having this issue even I upgraded to 3.0 rc1 My code is at https://dotnetfiddle.net/5rUTaW if I change the |
@xcaptain 3.0 rc1 doesn't contain this fix, you need to use Newtonsoft.Json, or try the daily build |
@Zonciu Thanks |
Here's what's causing the StackOverflow:
Original text:
From @Zonciu on Tuesday, September 10, 2019 2:16:16 PM
Describe the bug
WebApi returning specific content cause stack overflow
To Reproduce
Reproduction project
WebApplication.zip
Steps to reproduce the behavior:
/test/1
is ok, but/test/2
causing stack overflow and crashed.Expected behavior
Access
/test/2
, return{"name":"测试1"}
Screenshots
/test/1
/test/2
Additional context
dotnet --info output
Copied from original issue: dotnet/aspnetcore#13856
The text was updated successfully, but these errors were encountered: