<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:11:38 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-1123] Defective JSON string lets API bson_json_reader_read() crashed rather than returning error</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-1123</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;I using bson_json_reader_read() in my service to convert JSON string to BSON data.&lt;br/&gt;
But if the JSON string has defective in MongoDB extended JSON fields, the function bson_json_reader_read() will crash rather than return error.&lt;/p&gt;

&lt;p&gt;These are three cases:&lt;br/&gt;
---------------------&lt;br/&gt;
case 1&lt;br/&gt;
---------------------&lt;br/&gt;
JSON string: {&quot;$date&quot; : { &quot;$numberLong&quot; : &quot;1455853006123&quot;}}&lt;/p&gt;

&lt;p&gt;screen output:&lt;br/&gt;
src/bson/bson.c:1607 bson_append_date_time(): precondition failed: key&lt;/p&gt;

&lt;p&gt;crashed service stack by gdb:&lt;br/&gt;
---------------------&lt;br/&gt;
#0  0x00007ffff5c485c9 in raise () from /lib64/libc.so.6&lt;br/&gt;
#1  0x00007ffff5c49cd8 in abort () from /lib64/libc.so.6&lt;br/&gt;
#2  0x00007ffff6efbd47 in bson_append_date_time () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#3  0x00007ffff6f02fb3 in _bson_json_read_end_map () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#4  0x00007ffff6f0a80d in yajl_do_parse () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#5  0x00007ffff6f0345e in bson_json_reader_read () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#6  0x000000000044066f in MongoDBClient::Json2Bson (&lt;br/&gt;
    json=&quot;{\&quot;$date\&quot; : { \&quot;$numberLong\&quot; : \&quot;1455853006123\&quot;}}&quot;) at MongoDBClient.cpp:99&lt;br/&gt;
#7  0x0000000000444d0b in MongoDBProxyQuestProcessor::singleFind (this=this@entry=0xf8c018, args=&lt;br/&gt;
    std::shared_ptr (count 4, weak 0) 0xf4ce00, quest=std::shared_ptr (count 7, weak 0) 0xf4d580, &lt;br/&gt;
    hintId=hintId@entry=0, onlyHashTable=onlyHashTable@entry=false)&lt;br/&gt;
    at MongoDBProxyQuestProcessor.cpp:136&lt;/p&gt;


&lt;p&gt;---------------------&lt;br/&gt;
case 2&lt;br/&gt;
---------------------&lt;br/&gt;
JSON string: {&quot;$oid&quot; : { &quot;$numberLong&quot; : &quot;1455853006123&quot;}}&lt;/p&gt;

&lt;p&gt;screen output:&lt;br/&gt;
src/bson/bson.c:1144 bson_append_int64(): precondition failed: key&lt;/p&gt;

&lt;p&gt;crashed service stack by gdb:&lt;br/&gt;
---------------------&lt;br/&gt;
#0  0x00007ffff5c485c9 in raise () from /lib64/libc.so.6&lt;br/&gt;
#1  0x00007ffff5c49cd8 in abort () from /lib64/libc.so.6&lt;br/&gt;
#2  0x00007ffff6efb457 in bson_append_int64 () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#3  0x00007ffff6f0320c in _bson_json_read_end_map () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#4  0x00007ffff6f0a80d in yajl_do_parse () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#5  0x00007ffff6f0345e in bson_json_reader_read () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#6  0x000000000044066f in MongoDBClient::Json2Bson (&lt;br/&gt;
    json=&quot;{\&quot;$oid\&quot; : { \&quot;$numberLong\&quot; : \&quot;1455853006123\&quot;}}&quot;) at MongoDBClient.cpp:99&lt;br/&gt;
#7  0x0000000000444d0b in MongoDBProxyQuestProcessor::singleFind (this=this@entry=0xf8c018, args=&lt;br/&gt;
    std::shared_ptr (count 4, weak 0) 0xf4d640, quest=std::shared_ptr (count 7, weak 0) 0xf4d680, &lt;br/&gt;
    hintId=hintId@entry=0, onlyHashTable=onlyHashTable@entry=false)&lt;br/&gt;
    at MongoDBProxyQuestProcessor.cpp:136&lt;/p&gt;


&lt;p&gt;---------------------&lt;br/&gt;
case 3&lt;br/&gt;
---------------------&lt;br/&gt;
JSON string: &lt;/p&gt;
{&quot;$oid&quot; : &quot;563b029096f9bc35c61df3a3&quot;}

&lt;p&gt;screen output:&lt;br/&gt;
src/bson/bson.c:1405 bson_append_oid(): precondition failed: key&lt;/p&gt;

&lt;p&gt;crashed service stack by gdb:&lt;br/&gt;
---------------------&lt;br/&gt;
#0  0x00007ffff5c485c9 in raise () from /lib64/libc.so.6&lt;br/&gt;
#1  0x00007ffff5c49cd8 in abort () from /lib64/libc.so.6&lt;br/&gt;
#2  0x00007ffff6efb775 in bson_append_oid () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#3  0x00007ffff6f0305b in _bson_json_read_end_map () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#4  0x00007ffff6f0a80d in yajl_do_parse () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#5  0x00007ffff6f0345e in bson_json_reader_read () from /usr/lib64/libbson-1.0.so.0&lt;br/&gt;
#6  0x000000000044066f in MongoDBClient::Json2Bson (json=&quot;&lt;/p&gt;
{\&quot;$oid\&quot; : \&quot;563b029096f9bc35c61df3a3\&quot;}
&lt;p&gt;&quot;)&lt;br/&gt;
    at MongoDBClient.cpp:99&lt;br/&gt;
#7  0x0000000000444d0b in MongoDBProxyQuestProcessor::singleFind (this=this@entry=0xf8c018, args=&lt;br/&gt;
    std::shared_ptr (count 4, weak 0) 0xf4d440, quest=std::shared_ptr (count 7, weak 0) 0xf4d480, &lt;br/&gt;
    hintId=hintId@entry=0, onlyHashTable=onlyHashTable@entry=false)&lt;br/&gt;
    at MongoDBProxyQuestProcessor.cpp:136&lt;/p&gt;

&lt;p&gt;---------------------&lt;br/&gt;
 My convert function:&lt;br/&gt;
(Service is development by C++11 with Mongo C Driver.)&lt;br/&gt;
---------------------&lt;/p&gt;

&lt;p&gt;bson_t* MongoDBClient::Json2Bson(const std::string&amp;amp; json)&lt;br/&gt;
{&lt;br/&gt;
	const size_t buffsize = 512;&lt;br/&gt;
	bson_json_reader_t *reader = bson_json_data_reader_new(1, buffsize);&lt;br/&gt;
	if (reader == NULL)&lt;br/&gt;
		return NULL;&lt;/p&gt;

&lt;p&gt;	bson_json_data_reader_ingest(reader, (const uint8_t *)json.data(), json.length());&lt;/p&gt;

&lt;p&gt;	bson_error_t error;&lt;br/&gt;
	bson_t* doc = bson_new();&lt;br/&gt;
	bson_t* doc2 = bson_new();&lt;/p&gt;

&lt;p&gt;	int state = bson_json_reader_read (reader, doc, &amp;amp;error);&lt;br/&gt;
	if (state &amp;lt; 0)&lt;/p&gt;
	{
		bson_destroy (doc);
		bson_destroy (doc2);
		bson_json_reader_destroy (reader);
		LOG_ERROR(&quot;convert json %s to bson failed. error: %s&quot;, json.c_str(), error.message);
		return NULL;
	}

&lt;p&gt;	state = bson_json_reader_read (reader, doc2, &amp;amp;error);&lt;br/&gt;
	if (state != 0)&lt;/p&gt;
	{
		bson_destroy (doc);
		bson_destroy (doc2);
		bson_json_reader_destroy (reader);
		LOG_ERROR(&quot;convert json %s to bson failed. Json not a single object, reentered.&quot;, json.c_str());
		return NULL;
	}

&lt;p&gt;	bson_destroy (doc2);&lt;br/&gt;
	bson_json_reader_destroy (reader);&lt;/p&gt;

&lt;p&gt;	return doc;&lt;br/&gt;
}&lt;/p&gt;</description>
                <environment>Linux CentOS 7, gcc 4.8.2, g++ 4.8.2</environment>
        <key id="266674">CDRIVER-1123</key>
            <summary>Defective JSON string lets API bson_json_reader_read() crashed rather than returning error</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="jesse@mongodb.com">A. Jesse Jiryu Davis</assignee>
                                    <reporter username="swxlion">Wangxing Shi</reporter>
                        <labels>
                    </labels>
                <created>Fri, 19 Feb 2016 07:36:11 +0000</created>
                <updated>Sun, 27 Nov 2016 14:16:07 +0000</updated>
                            <resolved>Tue, 22 Mar 2016 02:11:36 +0000</resolved>
                                    <version>1.2.0</version>
                    <version>1.3.0</version>
                    <version>1.3.3</version>
                                    <fixVersion>1.4.0</fixVersion>
                                    <component>json</component>
                    <component>libbson</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="1210484" author="xgen-internal-githook" created="Tue, 22 Mar 2016 02:11:23 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;ajdavis&apos;, u&apos;name&apos;: u&apos;A. Jesse Jiryu Davis&apos;, u&apos;email&apos;: u&apos;jesse@mongodb.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-1123&quot; title=&quot;Defective JSON string lets API bson_json_reader_read() crashed rather than returning error&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-1123&quot;&gt;&lt;del&gt;CDRIVER-1123&lt;/del&gt;&lt;/a&gt; don&apos;t abort on bad extended JSON&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/libbson/commit/7debda43a7a70352f60eddf4c2c4ce2140cdd981&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/libbson/commit/7debda43a7a70352f60eddf4c2c4ce2140cdd981&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1179025" author="jesse" created="Fri, 19 Feb 2016 17:19:02 +0000"  >&lt;p&gt;Thanks so much for the detailed report.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="280364">CDRIVER-1202</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="299115">CDRIVER-1366</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <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|hrdelz:</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_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="918">C Driver 2016 sprint 3</customfieldvalue>
    <customfieldvalue id="959">C Driver 2016 sprint 4</customfieldvalue>

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