<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:08:40 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>[CDRIVER-172] mongo_read_response: insufficient memory allocated for &quot;out&quot;</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-172</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;Running &quot;tutorial_empty_query&quot; from &lt;a href=&quot;http://api.mongodb.org/c/current/tutorial.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://api.mongodb.org/c/current/tutorial.html&lt;/a&gt; on an empty database, I see that not enough memory is allocated for &quot;out&quot; in mongo_read_response (src/mongo.c). I added a printf:&lt;br/&gt;
   printf(&quot;mongo_read_response: %d required, %d allocated\n&quot;, sizeof(mongo_reply), len);&lt;br/&gt;
   out = ( mongo_reply * )bson_malloc( len ); // was here before&lt;/p&gt;

&lt;p&gt;And the output I get (tutorial_empty_query on empty database):&lt;br/&gt;
   mongo_read_response: 37 required, 106 allocated&lt;br/&gt;
   mongo_read_response: 37 required, 36 allocated // from mongo_cursor_next( cursor )&lt;/p&gt;

&lt;p&gt;In mongo_read_response (src/mongo.c) the check for &quot;len&quot; is:&lt;br/&gt;
   len &amp;lt; sizeof( head )+sizeof( fields )&lt;br/&gt;
Seems mongo_reply.objs is missing. Wouldn&apos;t something like:&lt;br/&gt;
   len &amp;lt; sizeof(mongo_reply)&lt;br/&gt;
be better? But this is just a check that fails to catch the problem. I guess the actual problem is that the requested &quot;len&quot; is too small. Not sure where that comes from.&lt;/p&gt;</description>
                <environment>32bit Linux&lt;br/&gt;
Server: &lt;a href=&quot;http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.2.0.tgz&quot;&gt;http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.2.0.tgz&lt;/a&gt;&lt;br/&gt;
Client: &lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/zipball/v0.6&quot;&gt;https://github.com/mongodb/mongo-c-driver/zipball/v0.6&lt;/a&gt;</environment>
        <key id="52883">CDRIVER-172</key>
            <summary>mongo_read_response: insufficient memory allocated for &quot;out&quot;</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="gjmurakami">Gary Murakami</assignee>
                                    <reporter username="marco2357">Marco</reporter>
                        <labels>
                    </labels>
                <created>Thu, 11 Oct 2012 09:29:33 +0000</created>
                <updated>Thu, 8 Aug 2013 16:31:14 +0000</updated>
                            <resolved>Thu, 8 Aug 2013 16:31:14 +0000</resolved>
                                    <version>0.6</version>
                                    <fixVersion>0.8.1</fixVersion>
                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="398763" author="gjmurakami" created="Thu, 8 Aug 2013 16:31:14 +0000"  >&lt;p&gt;While there is no functional problem, there is a poor coding practice problem that should otherwise be fixed, except that we are moving to a new C driver that is completely rewritten.  Closing won&apos;t fix.&lt;/p&gt;</comment>
                            <comment id="398759" author="gjmurakami" created="Thu, 8 Aug 2013 16:29:28 +0000"  >&lt;p&gt;Marco,&lt;/p&gt;

&lt;p&gt;I finally got around to looking at this.  My guess is that the original author (Kyle) added the objs field just for convenience in the code, the cursor next case with 37 versus 36 is where there are no objects in the response.  The existing code makes use of &quot;&amp;amp;out-&amp;gt;objs&quot; and &quot;&amp;amp;cursor-&amp;gt;reply-&amp;gt;objs&quot;.  This (objs) probably could be eliminated with &quot;&amp;amp;(out+1)&quot; and &quot;&amp;amp;(cursor-&amp;gt;reply+1)&quot; after objs is removed from mongo_reply.&lt;/p&gt;

&lt;p&gt;So while there is no functional problem here at the moment, I agree that it is not good coding practice, that objs should be removed from mongo_reply, and that this would fix the compiler complaint appropriately.  However, there is a completely rewritten C driver in the works, so we&apos;re focusing work there and minimizing work on this branch.&lt;/p&gt;

&lt;p&gt;So I&apos;m going to close this.  When the new rewritten driver is available, I would certainly welcome similar reports like this.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;/p&gt;

&lt;p&gt;-Gary&lt;/p&gt;</comment>
                            <comment id="247462" author="marco2357" created="Wed, 23 Jan 2013 11:25:42 +0000"  >&lt;p&gt;Are you surprised about sizeof(mongo_reply) = 37?&lt;br/&gt;
I&apos;m using Ubuntu 12.10, x86, gcc 4.4.7.&lt;br/&gt;
Also Red Hat 6.3, x64, gcc 4.4.6 has sizeof(mongo_reply) = 37.&lt;/p&gt;</comment>
                            <comment id="246655" author="gjmurakami" created="Tue, 22 Jan 2013 16:45:41 +0000"  >&lt;p&gt;Marco, thanks for your response. What environment/compiler are you using to get this report?&lt;/p&gt;</comment>
                            <comment id="245648" author="marco2357" created="Mon, 21 Jan 2013 15:46:33 +0000"  >&lt;p&gt;Hi Gary&lt;/p&gt;

&lt;p&gt;The code is still doing the same. With a requested &quot;len&quot; of 36, both versions will malloc 36:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;old: bson_malloc( len );&lt;/li&gt;
	&lt;li&gt;new: bson_malloc( sizeof(mongo_reply) - sizeof(char) + len - 16 - 20 ); // 37 - 1 + 36 - 16 - 20 = 36&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I&apos;m not sure if this addresses your concern from Jan 18 09:11, but it doesn&apos;t change the situation for me.&lt;/p&gt;

&lt;p&gt;Thanks&lt;br/&gt;
Marco&lt;/p&gt;</comment>
                            <comment id="243924" author="gjmurakami" created="Fri, 18 Jan 2013 21:49:03 +0000"  >&lt;p&gt;Marco, please check out the above commit and see if it addresses your issue (no more warning from your C compiler runtime).&lt;/p&gt;</comment>
                            <comment id="243922" author="auto" created="Fri, 18 Jan 2013 21:48:04 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2013-01-18T21:47:41Z&apos;, u&apos;email&apos;: u&apos;gary.murakami@10gen.com&apos;, u&apos;name&apos;: u&apos;Gary J. Murakami&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-172&quot; title=&quot;mongo_read_response: insufficient memory allocated for &amp;quot;out&amp;quot;&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-172&quot;&gt;&lt;del&gt;CDRIVER-172&lt;/del&gt;&lt;/a&gt; mongo_read_response: insufficient memory allocated for &quot;out&quot;&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/98826a1eaad779ea20a5f218f5b9e9591f30fd8b&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/commit/98826a1eaad779ea20a5f218f5b9e9591f30fd8b&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="243891" author="gjmurakami" created="Fri, 18 Jan 2013 21:11:57 +0000"  >&lt;p&gt;Marco, thanks for your response.  Yes, after examining this, there could be a problem.  While the message length on the wire is appropriately given, the mongo_reply struct could require more space due to differences in native type sizes versus wire type sizes and struct padding/packing.  I&apos;ll look into a fix.&lt;/p&gt;</comment>
                            <comment id="233984" author="marco2357" created="Tue, 8 Jan 2013 09:53:14 +0000"  >&lt;p&gt;I found it because I&apos;m using a C compiler respectively a runtime that warns about pointers with allocated areas that are not big enough for the type pointed to.&lt;br/&gt;
Since I never encountered an intentional case where insufficient memory was allocated for a struct pointer, I didn&apos;t look at the code too close before reporting. But I guess that this is the case here (no message; no memory for the &quot;objs&quot; field). Interesting!&lt;br/&gt;
So I guess this bug can be closed unless the design isn&apos;t deliberate after all.&lt;/p&gt;</comment>
                            <comment id="233422" author="gjmurakami" created="Mon, 7 Jan 2013 19:54:16 +0000"  >&lt;p&gt;What leads you to think that this is an issue?  Did the tutorial program crash?  Did you get some diagnostic?&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|hrjxvj:</customfieldvalue>

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