Skip to content

Commit 65ca1b1

Browse files
tejzprskriptble
authored andcommitted
GODRIVER-809 Fix panic while calling existing GridFS data
Fix for: https://jira.mongodb.org/browse/GODRIVER-809
1 parent 131e996 commit 65ca1b1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

mongo/gridfs/bucket.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"time"
1818

1919
"go.mongodb.org/mongo-driver/bson"
20+
"go.mongodb.org/mongo-driver/bson/bsontype"
2021
"go.mongodb.org/mongo-driver/bson/primitive"
2122
"go.mongodb.org/mongo-driver/mongo"
2223
"go.mongodb.org/mongo-driver/mongo/options"
@@ -346,7 +347,14 @@ func (b *Bucket) openDownloadStream(filter interface{}, opts ...*options.FindOpt
346347
return nil, err
347348
}
348349

349-
fileLen := fileLenElem.Int64()
350+
var fileLen int64
351+
switch fileLenElem.Type {
352+
case bsontype.Int32:
353+
fileLen = int64(fileLenElem.Int32())
354+
default:
355+
fileLen = fileLenElem.Int64()
356+
}
357+
350358
if fileLen == 0 {
351359
return newDownloadStream(nil, b.chunkSize, 0), nil
352360
}

0 commit comments

Comments
 (0)