<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:51:21 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>[JAVA-27] buffer overrun for large documents causes an exception for DBCursor.hasNext()</title>
                <link>https://jira.mongodb.org/browse/JAVA-27</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;I have some large documents (representing the contents of files in the 250K-1MB range) that cannot be read with the Java driver. The failure happens with DBCursor.hasNext():&lt;/p&gt;

&lt;p&gt;	public void catalog()&lt;br/&gt;
	{&lt;br/&gt;
		DBObject mdref = new BasicDBObject();&lt;br/&gt;
		mdref.put(&quot;metadata&quot;, 1);&lt;br/&gt;
		DBCursor cursor = this.coll.find();&lt;br/&gt;
		// the above line causes an error (the following line works ok)&lt;br/&gt;
		// DBCursor cursor = this.coll.find(new BasicDBObject(), mdref);&lt;br/&gt;
		System.out.println(&quot;Found &quot;&lt;ins&gt;cursor.count()&lt;/ins&gt;&quot; objects.&quot;);&lt;br/&gt;
		while (cursor.hasNext())&lt;/p&gt;
		{
			DBObject obj = cursor.next();
			System.out.println(obj);
		}
&lt;p&gt;	}&lt;/p&gt;

&lt;p&gt;When I run this on my database collection, I get the following. The call to find() succeeds, and the cursor&apos;s count() method works ok, but it bombs on the first hasNext() call, looks like some kind of buffer overrun.&lt;/p&gt;

&lt;p&gt;Found 10 objects.&lt;br/&gt;
Exception in thread &quot;main&quot; java.lang.IndexOutOfBoundsException&lt;br/&gt;
	at java.nio.Buffer.checkBounds(Unknown Source)&lt;br/&gt;
	at java.nio.DirectByteBuffer.get(Unknown Source)&lt;br/&gt;
	at com.mongodb.ByteDecoder.decodeNext(ByteDecoder.java:189)&lt;br/&gt;
	at com.mongodb.ByteDecoder.readObject(ByteDecoder.java:103)&lt;br/&gt;
	at com.mongodb.DBApiLayer$SingleResult.&amp;lt;init&amp;gt;(DBApiLayer.java:538)&lt;br/&gt;
	at com.mongodb.DBApiLayer$MyCollection.find(DBApiLayer.java:419)&lt;br/&gt;
	at com.mongodb.DBCursor._check(DBCursor.java:214)&lt;br/&gt;
	at com.mongodb.DBCursor._hasNext(DBCursor.java:322)&lt;br/&gt;
	at com.mongodb.DBCursor.hasNext(DBCursor.java:347)&lt;br/&gt;
	at com.dekaresearch.tools.datasheets.Manager.catalog(Manager.java:45)&lt;br/&gt;
	at com.dekaresearch.tools.datasheets.Manager$Action$2.execute(Manager.java:21)&lt;br/&gt;
	at com.dekaresearch.tools.datasheets.Manager.main(Manager.java:69)&lt;/p&gt;</description>
                <environment>WinXP, Java SE 6u13, Mongo Java driver mongo-0.7.jar</environment>
        <key id="10526">JAVA-27</key>
            <summary>buffer overrun for large documents causes an exception for DBCursor.hasNext()</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="5">Cannot Reproduce</resolution>
                                        <assignee username="eliot">Eliot Horowitz</assignee>
                                    <reporter username="jmsachs">Jason Sachs</reporter>
                        <labels>
                    </labels>
                <created>Tue, 1 Sep 2009 11:55:30 +0000</created>
                <updated>Fri, 2 Oct 2009 11:38:55 +0000</updated>
                            <resolved>Tue, 15 Sep 2009 22:26:42 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="10758" author="eliot" created="Tue, 15 Sep 2009 22:26:42 +0000"  >&lt;p&gt;seems to be a PHP issue&lt;/p&gt;</comment>
                            <comment id="10645" author="jmsachs" created="Fri, 4 Sep 2009 17:16:40 +0000"  >&lt;p&gt;I&apos;ll try to code up a simple test case. Problem seems to be interoperation of PHP and JAVA operating on DBObjects containing binary data.&lt;/p&gt;</comment>
                            <comment id="10644" author="eliot" created="Fri, 4 Sep 2009 16:10:24 +0000"  >&lt;p&gt;I&apos;m having trouble reproducing&lt;br/&gt;
Just added some more debugging.&lt;br/&gt;
can you use the latest code from github and give it a try.&lt;/p&gt;</comment>
                            <comment id="10608" author="jmsachs" created="Tue, 1 Sep 2009 13:44:39 +0000"  >&lt;p&gt;Well, I can&apos;t seem to get it to fail if I use Java to write in data, rather than PHP. The following program seems to read/write fine:&lt;/p&gt;

&lt;p&gt;	public void testbugJava27(String charsetName) throws UnknownHostException, MongoException, UnsupportedEncodingException&lt;br/&gt;
	{&lt;br/&gt;
		StringBuilder bigString = new StringBuilder();&lt;br/&gt;
		for (int i = 0; i &amp;lt; 5000; ++i)&lt;/p&gt;
		{
			bigString.append(&quot;Line &quot;+i+&quot; contains &apos;abcdabcdefghefgh&apos;\n&quot;);
		}
&lt;p&gt;		String s1 = bigString.toString();&lt;/p&gt;

&lt;p&gt;		StringBuilder sb = new StringBuilder();&lt;br/&gt;
		Mongo db = new Mongo( &quot;127.0.0.1&quot;, &quot;testdb&quot; );&lt;br/&gt;
		DBCollection coll = db.getCollection(&quot;test&quot;);&lt;br/&gt;
		coll.drop();&lt;br/&gt;
		String[] daysOfChristmas = &lt;/p&gt;
{
			&quot;a partridge in a pear tree&quot;,
			&quot;two turtle doves&quot;,
			&quot;three french hens&quot;,
			&quot;four calling birds&quot;,
			&quot;five golden rings&quot;,
			&quot;six geese a-laying&quot;,
			&quot;seven swans a-swimming&quot;,
			&quot;eight maids a-milking&quot;,
			&quot;nine ladies dancing&quot;,
			&quot;ten lords a-leaping&quot;,
			&quot;eleven pipers piping&quot;,
			&quot;twelve drummers drumming&quot;,
		}
&lt;p&gt;;&lt;br/&gt;
		String[] suffixes = &lt;/p&gt;
{&quot;st&quot;,&quot;nd&quot;,&quot;rd&quot;,&quot;th&quot;}
&lt;p&gt;; &lt;/p&gt;

&lt;p&gt;		for (int k = 0; k &amp;lt; daysOfChristmas.length; ++k)&lt;br/&gt;
		{			&lt;br/&gt;
			DBObject obj = new BasicDBObject();&lt;br/&gt;
			DBObject md = new BasicDBObject();&lt;br/&gt;
			md.put(&quot;foo&quot;, 123);&lt;br/&gt;
			md.put(&quot;bar&quot;, 456);&lt;br/&gt;
			md.put(&quot;k&quot;, k);&lt;br/&gt;
			obj.put(&quot;metadata&quot;, md);&lt;/p&gt;

&lt;p&gt;			sb.append(s1);&lt;br/&gt;
			sb.append(&quot;On the &quot;&lt;ins&gt;(k+1)+suffixes&lt;span class=&quot;error&quot;&gt;&amp;#91;k&amp;gt;3?3:k&amp;#93;&lt;/span&gt;&lt;/ins&gt;&quot; day of Christmas my true love sent to me:\n&quot;);&lt;br/&gt;
			for (int j = k; j &amp;gt;= 0; --j)&lt;/p&gt;
			{
				if (j == 0 &amp;amp;&amp;amp; k &amp;gt; 0)
					sb.append(&quot;and &quot;);
				sb.append(daysOfChristmas[j]);				
				sb.append(j == 0 ? &quot;.\n&quot; : &quot;,\n&quot;);
			}
&lt;p&gt;			String s = sb.toString();&lt;br/&gt;
			byte[] data;&lt;br/&gt;
			if (&quot;evil&quot;.equals(charsetName))&lt;br/&gt;
			{&lt;br/&gt;
				data = s.getBytes();&lt;br/&gt;
				int L = data.length;&lt;br/&gt;
				int N = 1000;&lt;br/&gt;
				Random r = new Random();&lt;br/&gt;
				r.setSeed(12345);&lt;br/&gt;
				for (int i = 0; i &amp;lt; N; ++i)&lt;/p&gt;
				{
					data[i] = (byte)r.nextInt(256);
				}
&lt;p&gt;			}&lt;br/&gt;
			else&lt;/p&gt;
			{
				data = charsetName == null ? s.getBytes() : s.getBytes(charsetName);
			}

&lt;p&gt;			obj.put(&quot;data&quot;, data);&lt;br/&gt;
			coll.save(obj);&lt;br/&gt;
		}&lt;/p&gt;

&lt;p&gt;		DBCursor cursor = coll.find();&lt;br/&gt;
		final int N = 400;&lt;br/&gt;
		while (cursor.hasNext())&lt;/p&gt;
		{
			DBObject obj = cursor.next();
			System.out.println(obj.get(&quot;metadata&quot;));
			Object d = obj.get(&quot;data&quot;);
			String s = new String((byte[])d);
			int l = s.length();
			System.out.println(&quot;length=&quot;+l);
			
			System.out.println(&quot;last &quot;+N+&quot; chars = &quot;+s.substring(l-N, l));
		}
&lt;p&gt;	}&lt;/p&gt;</comment>
                            <comment id="10607" author="jmsachs" created="Tue, 1 Sep 2009 13:03:57 +0000"  >&lt;p&gt;Hmmm. My database seems to have UTF-8 issues so maybe this isn&apos;t a buffer overrun issue per se. (see &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-174&quot; title=&quot;Crash in shell&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-174&quot;&gt;&lt;del&gt;SERVER-174&lt;/del&gt;&lt;/a&gt;). I&apos;ll try to reproduce with &quot;plain&quot; data.&lt;/p&gt;</comment>
                            <comment id="10605" author="jmsachs" created="Tue, 1 Sep 2009 12:22:02 +0000"  >&lt;p&gt;p.s. from the Red Herring Clarification Department:&lt;/p&gt;

&lt;p&gt;Those lines about it succeeding if I used additional arguments to find() are because my document contains a &quot;metadata&quot; field (small sub-object) and a &quot;data&quot; field (large), so if I download only the &quot;metadata&quot; field it works fine.&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|hrhdnr:</customfieldvalue>

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