<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:51 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-1170] When GetHashCode() is called from BsonElement with circular reference - overflow exception is thrown</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1170</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Please consider the following code:&lt;/p&gt;

&lt;p&gt;            var item1 = new BsonDocument();&lt;br/&gt;
            var item2 = new BsonDocument();&lt;br/&gt;
            item1.Add(new BsonElement(&quot;cycle_1&quot;, item2));&lt;br/&gt;
            item2.Add(new BsonElement(&quot;cycle_2&quot;, item1));&lt;/p&gt;

&lt;p&gt;Now, If I call item1.GetHashCode(), the application will terminate due to stack overflow exception (in my case I tried to add item1 to HashSet).&lt;br/&gt;
Sure an exception should be thrown, but stackoverflow exception terminates a .NET application. I looked in the source code, and saw that BsonDocument.GetHashCode also calls GetHashCode of inner elements, which in this case cause the infinite loop. &lt;br/&gt;
Is this considered a bug, or should the programmer know he should avoid such scenarios?&lt;/p&gt;</description>
                <environment></environment>
        <key id="180674">CSHARP-1170</key>
            <summary>When GetHashCode() is called from BsonElement with circular reference - overflow exception is thrown</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="2">Won&apos;t Fix</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="shaye">Shay</reporter>
                        <labels>
                    </labels>
                <created>Sun, 25 Jan 2015 14:29:13 +0000</created>
                <updated>Tue, 30 Aug 2016 17:16:32 +0000</updated>
                            <resolved>Tue, 30 Aug 2016 17:16:32 +0000</resolved>
                                                                    <component>BSON</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="1372104" author="rstam" created="Tue, 30 Aug 2016 17:16:32 +0000"  >&lt;p&gt;Checking for circular references would be expensive because we would have to track which nodes we have already visited.&lt;/p&gt;

&lt;p&gt;If we do that with a bit we have to make sure to clear that bit after the hash code is computed, requiring a second pass over the object graph. Also, this would not be multi thread safe.&lt;/p&gt;

&lt;p&gt;If we do that with a Dictionary we have the extra expense of looking up every node in the dictionary as we traverse the object graph.&lt;/p&gt;

&lt;p&gt;Since we don&apos;t intend to support circular references in the first place it seems unnecessary to slow down normal operations just to detect circular references.&lt;/p&gt;

&lt;p&gt;I&apos;m closing this as won&apos;t fix.&lt;/p&gt;</comment>
                            <comment id="1372089" author="dana.groff" created="Tue, 30 Aug 2016 17:09:52 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=rstam&quot; class=&quot;user-hover&quot; rel=&quot;rstam&quot;&gt;rstam&lt;/a&gt;Any further comments or interest?  Should we just close this as won&apos;t fix?&lt;/p&gt;</comment>
                            <comment id="812877" author="shaye" created="Mon, 26 Jan 2015 07:19:44 +0000"  >&lt;p&gt;Hi Robert,&lt;/p&gt;

&lt;p&gt;Thank you for your answer. &lt;br/&gt;
Why would checking for circular reference would be so expensive? We could mark visited nodes, and throw an exception when we visit the same node twice. For that matter we could use pointers hash set. &lt;br/&gt;
I&apos;m new here, so if I&apos;m talking nonsense please be kind &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt; &lt;/p&gt;
</comment>
                            <comment id="812767" author="rstam" created="Sun, 25 Jan 2015 21:58:04 +0000"  >&lt;p&gt;The BsonDocument object model is not intended to be used with circular references, and they are not supported.&lt;/p&gt;

&lt;p&gt;While getting a StackOverflowException when calling GetHashCode is unfortunate, it would be rather expensive to check for circular references every time GetHashCode is called, so we just assume that our users have not created circular references.&lt;/p&gt;

&lt;p&gt;Technically this &lt;b&gt;could&lt;/b&gt; be called a bug (because GetHashcode is never supposed to throw an exception), but given the obstacles in avoiding this StackOverflowException it is unlikely we will attempt to detect circular references to avoid this.&lt;/p&gt;

&lt;p&gt;I&apos;m going to leave the ticket open for further comments before a final decision is made.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hs5r73:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>158686</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>