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

DYN-6468 Add Guard for circular references that can impact Stringify.JSON and Remember node #14651

Merged
merged 3 commits into from
Dec 1, 2023

Conversation

saintentropy
Copy link
Contributor

@saintentropy saintentropy commented Nov 29, 2023

Purpose

In testing the Remember node we found that some classes of NET objects can cause Dynamo Crashes when Stringify.JSON tries to serialize the objects to JSON via json.net. The main example cases were some types of Revit objects. While it is expected that these objects should not serialize to json. They should fail with a warning on the node and not a hard crash.

Todo

  • Test
  • Add warning to localization.

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated
  • This PR contains no files larger than 50 MB

Release Notes

(FILL ME IN) Brief description of the fix / enhancement. Mandatory section

Reviewers

@mjkkirschner

FYIs

@jnealb

}
};

StringBuilder sb = new StringBuilder(256);
Copy link
Member

Choose a reason for hiding this comment

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

why was this capacity chosen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just copied what was in the internal implementation for Json.Net for JsonConvert.SerializeObject which looks like the new code but without the overridden JsonTextWriter

};

StringBuilder sb = new StringBuilder(256);
using (var writer = new StringWriter(sb, CultureInfo.InvariantCulture))
Copy link
Member

Choose a reason for hiding this comment

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

does json.net usually use invariant culture to serialize strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently... Again just duplicated the implementation.

private readonly int maxDepth = 15;
private int depth = 0;

public MaxDepthJsonTextWriter(TextWriter writer) : base(writer) { }
Copy link
Member

Choose a reason for hiding this comment

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

maybe allow setting the depth in the constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had it that way but simplified it since we aren't using this anywhere else currently. Right now one place to set it.

@mjkkirschner
Copy link
Member

regression test would be good.

@saintentropy saintentropy merged commit 7fdfc7f into DynamoDS:master Dec 1, 2023
19 checks passed
@saintentropy saintentropy deleted the DYN-6468 branch December 1, 2023 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants