<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:06 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-527] Custom Gt/Gte/Lt/Lte filter builders for unsigned integer fields represented using signed integers</title>
                <link>https://jira.mongodb.org/browse/CSHARP-527</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;The new typed query builder in 1.5 does not correctly convert queries when dealing with signed &amp;lt;-&amp;gt; unsigned conversions and GTE, LTE, GT, LT operations. Consider:&lt;/p&gt;

&lt;p&gt;class Foo&lt;br/&gt;
{&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonElement(&amp;quot;bar&amp;quot;)&amp;#93;&lt;/span&gt;&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonRepresentation(BsonType.Int32, AllowOverflow = true)&amp;#93;&lt;/span&gt;&lt;br/&gt;
public uint Bar &lt;/p&gt;
{ get; set; }
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Query&amp;lt;Foo&amp;gt;.GTE(f =&amp;gt; f.Bar, (uint)int.MaxValue + 1) // Error, needs to execute $lt : 0, but instead executes $gte : -2147483648, which is always true&lt;/p&gt;

&lt;p&gt;Marked this critical because while folks can work around this, it is counter intuitive and assuming the bug is fixed properly, will cause breaking changes that silently lead to corruption or undefined state for anyone that starts using these APIs like this.&lt;/p&gt;</description>
                <environment>All</environment>
        <key id="44188">CSHARP-527</key>
            <summary>Custom Gt/Gte/Lt/Lte filter builders for unsigned integer fields represented using signed integers</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="2" iconUrl="https://jira.mongodb.org/images/icons/priorities/critical.svg">Critical - P2</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="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="optimiz3">Alexander Nagy</reporter>
                        <labels>
                    </labels>
                <created>Sat, 14 Jul 2012 00:16:36 +0000</created>
                <updated>Wed, 19 Oct 2016 14:16:10 +0000</updated>
                            <resolved>Tue, 18 Oct 2016 20:52:39 +0000</resolved>
                                    <version>1.5</version>
                                    <fixVersion>2.4</fixVersion>
                                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="1411994" author="xgen-internal-githook" created="Tue, 18 Oct 2016 20:52:08 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;rstam&apos;, u&apos;name&apos;: u&apos;rstam&apos;, u&apos;email&apos;: u&apos;robert@robertstam.org&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-527&quot; title=&quot;Custom Gt/Gte/Lt/Lte filter builders for unsigned integer fields represented using signed integers&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-527&quot;&gt;&lt;del&gt;CSHARP-527&lt;/del&gt;&lt;/a&gt;: Custom Gt/Gte/Lt/Lte filter builders for unsigned integer fields represented using signed integers.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/ed93b64cb7129114076ed23cb2a1be071cd62f1e&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/ed93b64cb7129114076ed23cb2a1be071cd62f1e&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1406707" author="rstam" created="Wed, 12 Oct 2016 19:40:14 +0000"  >&lt;p&gt;Note: this issue was reported against the 1.x driver and is being resolved in the 2.x driver.&lt;/p&gt;

&lt;p&gt;We will not be backporting this change to the 1.x driver.&lt;/p&gt;</comment>
                            <comment id="143020" author="optimiz3" created="Sun, 15 Jul 2012 03:45:06 +0000"  >&lt;p&gt;That sounds right - depending on the direction of the operation and comparand, one or two clauses may be needed. Some minor optimization might be possible via switching and -&amp;gt; not or depending on the optimizer, but I&apos;m not not aware of any arithmetic or bit-twiddling hacks as long as the encoded representation is a direct cast of the input type. Certainly in any case where possible, only one query clause should be executed.&lt;/p&gt;</comment>
                            <comment id="142987" author="craiggwilson" created="Sat, 14 Jul 2012 13:25:59 +0000"  >&lt;p&gt;Ok, I see now what is going on.  It&apos;s actually more likely that simply $lt : 0 is not enough in a majority of cases.  Robert pointed out that we actually need extra conditions.&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;Query&amp;lt;Foo&amp;gt;.GTE(x =&amp;gt; x.Bar, (uint)int.MaxValue + 10 };&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;should render to this query: { bar : &lt;/p&gt;
{ $lt : 0, $gt : -2147483638 }
&lt;p&gt; }&lt;/p&gt;

&lt;p&gt;Likewise...&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;Query&amp;lt;Foo&amp;gt;.GTE(x =&amp;gt; x.Bar, 5);&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;...this should render even slightly different: { $or : [ { bar : &lt;/p&gt;
{ $gt : 5 }
&lt;p&gt; }, { bar : &lt;/p&gt;
{ $lt : 0 }
&lt;p&gt; } ] }&lt;/p&gt;

&lt;p&gt;Does that seem right to you?  If so, this is not a trivial problem.  We&apos;ll keep you in the loop as to what we come up with.&lt;/p&gt;</comment>
                            <comment id="142954" author="optimiz3" created="Sat, 14 Jul 2012 01:55:27 +0000"  >&lt;p&gt;The AllowOverflow in the example is more of a distraction - $lt : 0 for an int32 should be logically equivalent to $gte 0x80000000 for an uint32, assuming the uint32 is represented as an int32.&lt;/p&gt;

&lt;p&gt;The problem is that query being executed isn&apos;t respecting the semantics of the input type, even though it is at the encoding level, which is inconsistent with the rest of the typed query API (one could argue the whole reason why the effort is made with the serialization info inspection).  &lt;/p&gt;

&lt;p&gt;I.e. Query.GTE(&quot;bar&quot;, 0x80000000U) will always return nothing because there will be a type mismatch (int32 vs int64), but Query&amp;lt;Foo&amp;gt;(q =&amp;gt; q.Bar, 0x80000000U) one would expect to execute correctly because the typed version knows the encoding semantics of the type.&lt;/p&gt;

&lt;p&gt;Also notably, it is correct that -2147483648 be serialized to the database - but not in a query like this.&lt;/p&gt;

&lt;p&gt;This is definitely not an academic case, we checked in several mitigations on our side today due to this.&lt;/p&gt;

&lt;p&gt;EDIT: grammar, improve example&lt;/p&gt;</comment>
                            <comment id="142946" author="craiggwilson" created="Sat, 14 Jul 2012 01:21:28 +0000"  >&lt;p&gt;@Alex: why do you think it should resolve to 0?  AllowOverflow doesn&apos;t mean (no negative numbers). Rather, it indicates whether going over the maximum value is allowed and, if so, we do what the .NET framework does natively.  This isn&apos;t a typed builder problem either.  If you look at the UInt32Serializer, you&apos;ll see we defer to the RepresentationSerializationOptions to give us a value. &lt;/p&gt;

&lt;p&gt;Furthermore, if you tried to save this:&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;collection.Save(new Foo{ Bar = (uint)int.MaxValue + 1 });&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;It would save with -2147483648.  Hence, the typed builders render the query in the same way that it would get serialized.&lt;/p&gt;

&lt;p&gt;On a separate not, was this purely academic or do you have a class like this?&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|hrcbo7:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>82188</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="1329">C# Sprint 43</customfieldvalue>

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