<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 05:16:41 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>[SERVER-48286] Handle accuracy issues of casting long long to double</title>
                <link>https://jira.mongodb.org/browse/SERVER-48286</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;A &lt;tt&gt;double&lt;/tt&gt; on 64-bit architectures uses 1 bit for sign, 52 bits for value, and 11 bits for exponent, thus, the maximum integer value that it can contain without losing precision is &lt;tt&gt;0x1FFFFFFFFFFFFF&lt;/tt&gt; (9,007,199,254,740,991).&#160;This is much smaller than &lt;tt&gt;LLONG_MAX&lt;/tt&gt; (9,223,372,036,854,775,807) and the range &lt;tt&gt;long long&lt;/tt&gt; covers.&lt;/p&gt;

&lt;p&gt;There are instances that we cast &lt;tt&gt;LLONG_MAX&lt;/tt&gt; to &lt;tt&gt;double&lt;/tt&gt; and do a comparison (&lt;a href=&quot;https://github.com/mongodb/mongo/blob/04a84eed3ad636e8f9f76b0c48621332e50f8535/src/mongo/bson/bsonelement.h#L898&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;see here&lt;/a&gt;. We should ensure the accuracy of such comparisons in presence of values that cause precision issues for &lt;tt&gt;double&lt;/tt&gt;.&lt;/p&gt;</description>
                <environment></environment>
        <key id="1355227">SERVER-48286</key>
            <summary>Handle accuracy issues of casting long long to double</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</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="justin.seyster@mongodb.com">Justin Seyster</assignee>
                                    <reporter username="amirsaman.memaripour@mongodb.com">Amirsaman Memaripour</reporter>
                        <labels>
                    </labels>
                <created>Tue, 19 May 2020 00:28:51 +0000</created>
                <updated>Tue, 26 May 2020 21:12:48 +0000</updated>
                            <resolved>Tue, 26 May 2020 21:12:48 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>8</watches>
                                                                                                                <comments>
                            <comment id="3111522" author="justin.seyster" created="Tue, 26 May 2020 21:12:38 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=amirsaman.memaripour&quot; class=&quot;user-hover&quot; rel=&quot;amirsaman.memaripour&quot;&gt;amirsaman.memaripour&lt;/a&gt;, thanks for the investigative work on this issue! You are right that the check at&#160;&lt;a href=&quot;#L898]&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;bsonelement.h:898&lt;/a&gt; relies on undefined behavior: the result of&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;(double)std::numeric_limits&amp;lt;long long&amp;gt;::max()&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;can actually vary depending on the hardware architecture and/or the software environment. The result is a very rare edge case, where on some architectures (in practice, most) this check considers the exact value double{2^63} as be safe for conversion (i.e., within the range of long long) when it actually is not. Casting double{2^63} to long long is also undefined behavior, and we have observed different outcomes (including crashing).&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;We fixed this problem in&#160;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-38623&quot; title=&quot;Make safeNumberLongForHash consistent between PPC and other architectures&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-38623&quot;&gt;&lt;del&gt;SERVER-38623&lt;/del&gt;&lt;/a&gt;, which landed in v4.2, but for compatibility reasons, we can&apos;t backport the fix to v4.0. The result of safeNumberLongForHash() gets stored in on-disk indexes, and any change in its behavior could effectively corrupt those indexes. The upgrade instructions for v4.2 include specific steps to make sure that any affected indexes get rebuilt so as to make sure the remain valid with the modified hashing semantics.&lt;/p&gt;

&lt;p&gt;If you&apos;re interested in the gory details, you can read through the discussions in&#160;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-37183&quot; title=&quot;BSONElement::safeNumberLong is not safe&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-37183&quot;&gt;&lt;del&gt;SERVER-37183&lt;/del&gt;&lt;/a&gt; and&#160;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-38623&quot; title=&quot;Make safeNumberLongForHash consistent between PPC and other architectures&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-38623&quot;&gt;&lt;del&gt;SERVER-38623&lt;/del&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Because this is fixed in v4.2 but can&apos;t be backported, I&apos;m going to close as &quot;Won&apos;t fix.&quot;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="3095118" author="milkie" created="Tue, 19 May 2020 15:16:26 +0000"  >&lt;p&gt;That second code location is for numberLong(), for which safeNumberLong() was created to avoid the problems of casting double to long long.  I wonder if we should try to work towards getting rid of the unsafe numberLong() function &amp;#8211; its usage is pervasive across the codebase, unfortunately.&lt;/p&gt;</comment>
                            <comment id="3095108" author="amirsaman.memaripour" created="Tue, 19 May 2020 15:12:02 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=milkie&quot; class=&quot;user-hover&quot; rel=&quot;milkie&quot;&gt;milkie&lt;/a&gt; I think it&apos;s also possible to fix the issue by changing &lt;tt&gt;&amp;gt;&lt;/tt&gt; to &lt;tt&gt;&amp;gt;=&lt;/tt&gt; &lt;a href=&quot;https://github.com/mongodb/mongo/blob/04a84eed3ad636e8f9f76b0c48621332e50f8535/src/mongo/bson/bsonelement.h#L898&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;in here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Regarding other instances, I&apos;m not sure if they could cause any issues, but another cast (that could potentially cause issues) is &lt;a href=&quot;https://github.com/mongodb/mongo/blob/51d9fe12b5d19720e72dcd7db0f2f17dd9a19212/src/mongo/bson/bsonelement.h#L870&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;this one&lt;/a&gt;.&lt;/p&gt;</comment>
                            <comment id="3095055" author="milkie" created="Tue, 19 May 2020 14:55:12 +0000"  >&lt;p&gt;The idea of the code change in &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-37183&quot; title=&quot;BSONElement::safeNumberLong is not safe&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-37183&quot;&gt;&lt;del&gt;SERVER-37183&lt;/del&gt;&lt;/a&gt; was to preserve the undefined-behavior for hashing only.  It doesn&apos;t matter that it is losing precision as long as the behavior remains the same and creates the same hash value for a given double on a given platform.  We might need to do something to get the UBSAN to ignore this particular area.&lt;/p&gt;

&lt;p&gt;The Description of this ticket says there are instances plural &amp;#8211; where else in the code are we doing this?&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                                                <inwardlinks description="is depended on by">
                                                        </inwardlinks>
                                    </issuelinktype>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="606452">SERVER-37183</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>4.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18555" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname># of Sprints</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1.0</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 19 May 2020 14:55:12 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        3 years, 37 weeks, 1 day ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>justin.seyster@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            3 years, 37 weeks, 1 day ago
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_16465" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Linked BF Score</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>0.0</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10032" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Operating System</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10026"><![CDATA[ALL]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>amirsaman.memaripour@mongodb.com</customfieldvalue>
            <customfieldvalue>milkie@mongodb.com</customfieldvalue>
            <customfieldvalue>justin.seyster@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hxlv33:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr52sv:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="3607">Query 2020-06-15</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hxlhcf:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>