<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:38:17 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>[GODRIVER-2311] Byte array reuse in BSON unmarshalling may cause duplicated values</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-2311</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;Updated:&lt;br/&gt;
Confirmed this is a bug; conditions that will trigger this bug are:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Load a BSON document into a &lt;tt&gt;[]byte&lt;/tt&gt; (e.g. from a file, a server response, etc.)&lt;/li&gt;
	&lt;li&gt;Unmarshal the BSON document into any type that contains a &lt;tt&gt;[]byte&lt;/tt&gt; field, like a user-defined struct or &lt;tt&gt;bson.D&lt;/tt&gt;.&lt;/li&gt;
	&lt;li&gt;Modify the bytes in the input &lt;tt&gt;[]byte&lt;/tt&gt;.&lt;/li&gt;
	&lt;li&gt;Observe that the contents of the &lt;tt&gt;[]byte&lt;/tt&gt; field in the unmarshaled value changed.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Check out a repro example here (note that the example doesn&apos;t repro the problem on the Go Playground as of the 1.8.5/1.9.0 releases, which fix the bug): &lt;a href=&quot;https://go.dev/play/p/-BjGJ9OjAVB&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://go.dev/play/p/-BjGJ9OjAVB&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that this only applies to unmarshaling into byte slice values, not byte array values. For example, values unmarshaled to a struct containing a &lt;tt&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;16&amp;#93;&lt;/span&gt;byte&lt;/tt&gt; field are not affected. However, the same BSON document unmarshaled to a &lt;tt&gt;bson.D&lt;/tt&gt; will infer the value type is a &lt;tt&gt;[]byte&lt;/tt&gt; and will be affected.&lt;/p&gt;

&lt;p&gt;Original:&lt;br/&gt;
Some users of a &lt;a href=&quot;https://github.com/fsnow/mongopush&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongopush fork&lt;/a&gt; are having &lt;a href=&quot;https://github.com/fsnow/mongopush/issues/9&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;issues&lt;/a&gt; with duplication of UUIDs in unmarshalled values. Specifically, when reading an oplog written to a file &lt;a href=&quot;https://github.com/fsnow/mongopush/blob/df967f36248a64a68e9ab5243376526cbfa2f8ad/oplog_cache.go#L54&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;here&lt;/a&gt;, some UUID fields in the unmarshalled values can be duplicated.&lt;/p&gt;

&lt;p&gt;The duplication bug is fixed by &lt;a href=&quot;https://github.com/fsnow/mongopush/commit/c49c61e96d3b73c924db8291dd64ec7b2c1ab168&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;this commit&lt;/a&gt; which makes a copy of the input file byte buffer. That fix suggesting the root cause of the issue may be some input byte array reuse in the returned value (i.e. the BSON &lt;tt&gt;Unmarshal&lt;/tt&gt; function returns an unmarshalled value with byte slices that point to sections of the same byte array as the input data). That can lead to unexpected value duplication or corruption if the input byte array is modified after unmarshalling a value (modifying the input byte slice/array after &lt;tt&gt;Unmarshal&lt;/tt&gt; returns is a valid use case).&lt;/p&gt;

&lt;p&gt;Try to detect the possible issue using the following process:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Create a set of input structs containing different value types, including byte slice types (e.g. &lt;tt&gt;[]byte&lt;/tt&gt;, &lt;tt&gt;uuid.UUID&lt;/tt&gt;, etc).&lt;/li&gt;
	&lt;li&gt;Marshal each input struct value as BSON.&lt;/li&gt;
	&lt;li&gt;Record the low and high addresses of the output byte slice and underlying array.&lt;/li&gt;
	&lt;li&gt;Unmarshal the marshalled bytes into a &lt;tt&gt;bson.D&lt;/tt&gt;.&lt;/li&gt;
	&lt;li&gt;Record the low and high addresses of the byte slice-type values in the unmarshalled &lt;tt&gt;bson.D&lt;/tt&gt;.&lt;/li&gt;
	&lt;li&gt;Check if any of the byte slice-type value addresses are in the memory address range of the input byte slice/array.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;E.g. getting underlying array addresses of a slice:&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;   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;s := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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;   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;sh := (*reflect.SliceHeader)(unsafe.Pointer(&amp;amp;s))&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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;   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;fmt.Println(&quot;Low address&quot;, sh.Data)&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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-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;fmt.Println(&quot;High address&quot;, sh.Data+uintptr(sh.Cap-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;</description>
                <environment></environment>
        <key id="1983078">GODRIVER-2311</key>
            <summary>Byte array reuse in BSON unmarshalling may cause duplicated values</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="1" iconUrl="https://jira.mongodb.org/images/icons/priorities/blocker.svg">Blocker - P1</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="13201">Fixed</resolution>
                                        <assignee username="matt.dale@mongodb.com">Matt Dale</assignee>
                                    <reporter username="matt.dale@mongodb.com">Matt Dale</reporter>
                        <labels>
                    </labels>
                <created>Mon, 14 Feb 2022 18:31:35 +0000</created>
                <updated>Sat, 28 Oct 2023 11:37:38 +0000</updated>
                            <resolved>Wed, 16 Mar 2022 18:16:20 +0000</resolved>
                                    <version>1.0.4</version>
                                    <fixVersion>1.9.0</fixVersion>
                    <fixVersion>1.8.5</fixVersion>
                    <fixVersion>1.7.6</fixVersion>
                                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="4456004" author="xgen-internal-githook" created="Mon, 4 Apr 2022 19:55:06 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Kevin Albertson&apos;, &apos;email&apos;: &apos;kevin.albertson@mongodb.com&apos;, &apos;username&apos;: &apos;kevinAlbs&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-2311&quot; title=&quot;Byte array reuse in BSON unmarshalling may cause duplicated values&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-2311&quot;&gt;&lt;del&gt;GODRIVER-2311&lt;/del&gt;&lt;/a&gt; Ensure unmarshaled BSON values always use distinct unde&#8230; (#892)&lt;/p&gt;

&lt;p&gt;Co-authored-by: Matt Dale &amp;lt;9760375+matthewdale@users.noreply.github.com&amp;gt;&lt;br/&gt;
Branch: release/1.7&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/commit/8e61246c0fc22225809faa3f7115a2d89e16a389&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver/commit/8e61246c0fc22225809faa3f7115a2d89e16a389&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4446390" author="xgen-internal-githook" created="Thu, 31 Mar 2022 01:04:11 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Matt Dale&apos;, &apos;email&apos;: &apos;9760375+matthewdale@users.noreply.github.com&apos;, &apos;username&apos;: &apos;matthewdale&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-2311&quot; title=&quot;Byte array reuse in BSON unmarshalling may cause duplicated values&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-2311&quot;&gt;&lt;del&gt;GODRIVER-2311&lt;/del&gt;&lt;/a&gt; Improve the BSON unmarshal buffer reuse fix to reduce memory allocations. (#891)&lt;br/&gt;
Branch: release/1.8&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/commit/dac4668295fe7d553db2374530cbcec973682e21&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver/commit/dac4668295fe7d553db2374530cbcec973682e21&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4446387" author="xgen-internal-githook" created="Thu, 31 Mar 2022 00:58:20 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Matt Dale&apos;, &apos;email&apos;: &apos;9760375+matthewdale@users.noreply.github.com&apos;, &apos;username&apos;: &apos;matthewdale&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-2311&quot; title=&quot;Byte array reuse in BSON unmarshalling may cause duplicated values&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-2311&quot;&gt;&lt;del&gt;GODRIVER-2311&lt;/del&gt;&lt;/a&gt; Improve the BSON unmarshal buffer reuse fix to reduce memory allocations. (#891)&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/commit/5970415b5bdd318697fc75b2af93a7f724a44e89&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver/commit/5970415b5bdd318697fc75b2af93a7f724a44e89&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4427801" author="xgen-internal-githook" created="Tue, 22 Mar 2022 19:07:48 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Matt Dale&apos;, &apos;email&apos;: &apos;9760375+matthewdale@users.noreply.github.com&apos;, &apos;username&apos;: &apos;matthewdale&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-2311&quot; title=&quot;Byte array reuse in BSON unmarshalling may cause duplicated values&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-2311&quot;&gt;&lt;del&gt;GODRIVER-2311&lt;/del&gt;&lt;/a&gt; Ensure unmarshaled BSON values always use distinct underlying byte arrays. (#874)&lt;br/&gt;
Branch: release/1.8&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/commit/1bef05bfac11ae8fe7632e873fd7a91dbbf4da9d&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver/commit/1bef05bfac11ae8fe7632e873fd7a91dbbf4da9d&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4416440" author="xgen-internal-githook" created="Wed, 16 Mar 2022 18:15:16 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Matt Dale&apos;, &apos;email&apos;: &apos;9760375+matthewdale@users.noreply.github.com&apos;, &apos;username&apos;: &apos;matthewdale&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/GODRIVER-2311&quot; title=&quot;Byte array reuse in BSON unmarshalling may cause duplicated values&quot; class=&quot;issue-link&quot; data-issue-key=&quot;GODRIVER-2311&quot;&gt;&lt;del&gt;GODRIVER-2311&lt;/del&gt;&lt;/a&gt; Ensure unmarshaled BSON values always use distinct underlying byte arrays. (#874)&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/commit/d307af82c6ed70c51fd4576f87f128479c82ada0&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver/commit/d307af82c6ed70c51fd4576f87f128479c82ada0&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4411692" author="JIRAUSER1259527" created="Mon, 14 Mar 2022 22:55:32 +0000"  >&lt;p&gt;PR: &lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/pull/874&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver/pull/874&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                            <customfield id="customfield_21350" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Cloud Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="22240"><![CDATA[Needed]]></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_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i0376f:</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>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>