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

Suspicious code fragments in System.Text.Json #112344

Open
rip-mm opened this issue Feb 10, 2025 · 7 comments
Open

Suspicious code fragments in System.Text.Json #112344

rip-mm opened this issue Feb 10, 2025 · 7 comments
Labels
area-Debugger-mono help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@rip-mm
Copy link

rip-mm commented Feb 10, 2025

Description

Hello.

I have checked project using the PVS-Studio analyzer. The results of the check revealed a number of suspicious code fragments that I have included in an article. You may be interested in taking a look at them.

It's worth noting that the article contains only the most interesting warnings issued by the analyzer. You can check your project in more detail using the free version of PVS-Studio for open-source projects.

Reproduction Steps

Not required

Expected behavior

Not required

Actual behavior

Not required

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 10, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 10, 2025
@huoyaoyuan
Copy link
Member

Thank you for help to diagnose the code quality of runtime repository. The linked article is somehow verbose to read, and it doesn't contain links to the source code that we can identify quickly.

The analyzer reports are valid. Some are already fixed (#112090) by inspiration of your article. Some issues are in the test/debug suite which are less severe.

You are welcomed to submit pull requests to fix the issues. Please submit to main branch and we will backport real important fixes to existing releases.

@huoyaoyuan huoyaoyuan added area-Meta and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 10, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

@jeffhandley jeffhandley added help wanted [up-for-grabs] Good issue for external contributors needs-author-action An issue or pull request that requires more info or actions from the author. and removed untriaged New issue has not been triaged by the area owner labels Feb 10, 2025
@jeffhandley jeffhandley added this to the Future milestone Feb 10, 2025
Copy link
Contributor

This issue has been marked needs-author-action and may be missing some important information.

jkotas added a commit to jkotas/runtime that referenced this issue Feb 11, 2025
@jkotas
Copy link
Member

jkotas commented Feb 11, 2025

#112384 is fixing issues mentioned in the article that has not been fixed yet, except the ones in System.Text.Json.

@dotnet/area-system-text-json Please take a look at the issues in System.Text.Json

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.

@jkotas jkotas removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Feb 11, 2025
@jkotas jkotas changed the title Suspicious code fragments Suspicious code fragments in System.Text.Json Feb 11, 2025
@eiriktsarpalis
Copy link
Member

The JSON-related code fragments cited are the following:

public async Task<JObject> GetValueFromObject(JToken objRet, CancellationToken token)
{
if (objRet["value"]?["className"]?.Value<string>() == "System.Exception")
{
if (DotnetObjectId.TryParse(objRet?["value"]?["objectId"]?.Value<string>(), out DotnetObjectId objectId))
{
GetMembersResult exceptionObject = await MemberObjectsExplorer.GetTypeMemberValues(context.SdbAgent, objectId, GetObjectCommandOptions.WithProperties | GetObjectCommandOptions.OwnProperties, token);
var exceptionObjectMessage = exceptionObject.FirstOrDefault(attr => attr["name"].Value<string>().Equals("_message"));
exceptionObjectMessage["value"]["value"] = objRet["value"]?["className"]?.Value<string>() + ": " + exceptionObjectMessage["value"]?["value"]?.Value<string>();
return exceptionObjectMessage["value"]?.Value<JObject>();
}
return objRet["value"]?.Value<JObject>();
}

private static async Task<JArray> GetRootHiddenChildren(
MonoSDBHelper sdbHelper,
JObject root,
string rootNamePrefix,
string rootTypeName,
GetObjectCommandOptions getCommandOptions,
bool includeStatic,
CancellationToken token)
{
var rootValue = root?["value"] ?? root["get"];
if (rootValue?["subtype"]?.Value<string>() == "null")
return new JArray();

foreach (JObject frame in orig_callframes.Value["result"]?["value"]?["frames"])
{
string function_name = frame["displayName"]?.Value<string>();
if (function_name != null && !(function_name.StartsWith("Module._mono_wasm", StringComparison.Ordinal) ||
function_name.StartsWith("Module.mono_wasm", StringComparison.Ordinal) ||
function_name == "mono_wasm_fire_debugger_agent_message_with_data" ||
function_name == "_mono_wasm_fire_debugger_agent_message_with_data" ||
function_name == "(wasmcall)"))
{
callFrames.Add(frame);
}
}

They use Json.NET DOM types and are part of the browser debugger.

Copy link
Contributor

Tagging subscribers to this area: @thaystg
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Debugger-mono help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

5 participants