[CSHARP-1489] Read throws NullReferenceException when using a seekable download stream Created: 04/Dec/15  Updated: 19/Apr/18  Resolved: 07/Jan/16

Status: Closed
Project: C# Driver
Component/s: GridFS
Affects Version/s: 2.1
Fix Version/s: 2.2

Type: Bug Priority: Major - P3
Reporter: Rich Q Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7 x64



 Description   

In my application, I need to support downloading arbitrary chunks of a GridFS file per request. To do this, I'm using bucket.OpenDownloadStream (setting Seekable to True in the options), and Stream.Read.

I get a NullReferenceException in GridFSSeekableDownloadStream.GetSegment at:

var segmentCount = _chunk.Length - segmentOffset;

because _chunk is null.

Here is a test that can be added to GridFSDownloadStreamBaseTests

[Test]
        public void Read_should_not_throw(
            [Values(0.5, 1.0, 1.5, 2.0, 2.5)] double contentSizeMultiple,
            [Values(false, true)] bool async, 
            [Values(false, true)] bool seekable)
        {
            var bucket = CreateBucket(128);
            var contentSize = (int)(bucket.Options.ChunkSizeBytes * contentSizeMultiple);
            var content = CreateContent(contentSize);
            var id = CreateGridFSFile(bucket, content);
            var options = new GridFSDownloadOptions() {Seekable = seekable };
            var subject = bucket.OpenDownloadStream(id, options);
 
            var buffer = new byte[contentSize];
 
            if (async)
            {
                subject.ReadAsync(buffer, 0, contentSize).GetAwaiter().GetResult();
            }
            else
            {
                subject.Read(buffer, 0, contentSize);
            }            
        }



 Comments   
Comment by Githook User [ 07/Jan/16 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1489: Add more tests for GridFSSeekableDownloadStream.
Branch: v2.1.x
https://github.com/mongodb/mongo-csharp-driver/commit/2eb0d4753908abf77ab74aee3e8e9390973dcdae

Comment by Githook User [ 07/Dec/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1489: Add more tests for GridFSSeekableDownloadStream.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/971da14693c805b9030dd9cd8b2272b97cb8f82f

Comment by Githook User [ 07/Dec/15 ]

Author:

{u'name': u'rich.quackenbush', u'email': u'rich.quackenbush@captiveaire.com'}

Message: Fix for NullReferenceException for seekable download stream:
https://jira.mongodb.org/browse/CSHARP-1489
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/c3e55d9420d9a890113f2c087e2dda51781c06dc

Comment by Robert Stam [ 05/Dec/15 ]

Thank you for our pull request. I will be reviewing it soon.

Comment by Rich Q [ 04/Dec/15 ]

Pull request:
https://github.com/mongodb/mongo-csharp-driver/pull/227

Generated at Wed Feb 07 21:39:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.