[JAVA-378] ArrayIndexOutOfBoundsException at GridFSInputFile.java:353 when using chunksize > 256KB in GridFS Created: 11/Jun/11  Updated: 18/Jun/12  Resolved: 15/May/12

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 2.6.3
Fix Version/s: 2.8.0

Type: Bug Priority: Major - P3
Reporter: Joong Onn Assignee: Jeffrey Yemin
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

To produce the exception:


Mongo mongo = new Mongo("localhost", 27017);
GridFS gfs = new GridFS(mongo.getDB("bucket_test"));
GridFSInputFile file = gfs.createFile("512kb_bucket");
file.setChunkSize(512 * 1024);
OutputStream os = file.getOutputStream();
for (int i=0; i<32 * 1024 * 1024; i++)

{ os.write('.'); }

os.close();
mongo.close();


It appears that the private _buffer[] in GridFSInputFile.java should be resized as well in the setChunkSize(long _chunkSize) method. Eg.


public void setChunkSize(long _chunkSize)

{ if (_outputStream != null || _savedChunks) return; this._chunkSize = _chunkSize; _buffer = new byte[(int) _chunkSize]; // ######## Resize here? ######## }




 Comments   
Comment by Jeffrey Yemin [ 18/Jun/12 ]

Closing for 2.8.0 release.

Comment by auto [ 14/May/12 ]

Author:

{u'login': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-378: Added unit test
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/d355b367ce6f6d032468e9ab0d11946612b95a59

Comment by auto [ 12/May/12 ]

Author:

{u'login': u'rgnitz', u'name': u'Ryan', u'email': u'rgnitz@gmail.com'}

Message: Merge pull request #75 from lesnail/master

JAVA-378 reallocate buffer when changing chunksize of GridFsInputFile
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/4bd156ff670c5de64e8be6a461c9c76f3692420e

Comment by auto [ 12/May/12 ]

Author:

{u'login': u'', u'name': u'lesnail', u'email': u'thomas@scalableminds.com'}

Message: JAVA-378 reallocate buffer to correct size when changing chunksize of GridFSInputFile
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/cfcd2bfc87aba6554dd948f197a7dc7a9d230def

Generated at Thu Feb 08 08:52:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.