[GODRIVER-809] Go driver cannot decode gridfs files collection documents if the length field is not stored as int64 Created: 05/Feb/19  Updated: 28/Oct/23  Resolved: 26/Mar/19

Status: Closed
Project: Go Driver
Component/s: GridFS
Affects Version/s: None
Fix Version/s: 1.0.1

Type: Bug Priority: Major - P3
Reporter: Patrick Freed Assignee: Go Community User
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
backported by GODRIVER-957 Backport "Go driver cannot decode gri... Closed
Depends
is depended on by TOOLS-1833 Migrate tools (excluding mongoreplay)... Closed
Problem/Incident
is caused by PYTHON-1738 Length field of gridfs files collecti... Closed

 Description   

From the gridfs spec:

Note: drivers SHOULD store length as Int64 and chunkSize as Int32 when creating new GridFS files. However, drivers MUST be able to handle existing GridFS files where the length and chunkSize fields might have been stored using a different numeric data type.

However, the Go driver cannot handle existing GridFS files if the type of length (or chunkSize, presumably) is not int64.

To reproduce, insert some GridFS data using the python driver (which stores length as Int32) and try to read it with the Go driver. It will panic with output similar to this:

panic: Call of bsoncore.Value.Int64 on 32-bit integer type
 
goroutine 1 [running]:
github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/x/bsonx/bsoncore.Value.Int64(0x110, 0xc000300094, 0x4, 0x10c, 0x107)
        /Users/patrickfreed/go/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/x/bsonx/bsoncore/value.go:693 +0x18a
github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/bson.RawValue.Int64(0x10, 0xc000300094, 0x4, 0x10c, 0x0, 0x1)
        /Users/patrickfreed/go/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/bson/raw_value.go:273 +0x66
github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/mongo/gridfs.(*Bucket).openDownloadStream(0xc000278000, 0x1526180, 0xc000238480, 0xc000107a38, 0x1, 0x1, 0x0, 0x0, 0x0)
        /Users/patrickfreed/go/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/mongo/gridfs/bucket.go:341 +0x347
github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/mongo/gridfs.(*Bucket).OpenDownloadStreamByName(0xc000278000, 0x7ffeefbff6e0, 0xc, 0x0, 0x0, 0x0, 0x23, 0xc000107cf0, 0x1)
        /Users/patrickfreed/go/src/github.com/mongodb/mongo-tools/vendor/github.com/mongodb/mongo-go-driver/mongo/gridfs/bucket.go:214 +0x41f

 



 Comments   
Comment by Githook User [ 26/Mar/19 ]

Author:

{'name': 'Tejus Pratap', 'username': 'tejzpr', 'email': 'tejzpr@gmail.com'}

Message: GODRIVER-809 Fix panic while calling existing GridFS data

Fix for: https://jira.mongodb.org/browse/GODRIVER-809
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/51421e413403fe3c9b0097147841f752421133e4

Comment by Tejus Pratap [ 26/Mar/19 ]

Created a PR https://github.com/mongodb/mongo-go-driver/pull/151

Comment by Tejus Pratap [ 26/Mar/19 ]

GridFS and various implementations of it (PyMongo's for example) pre-date the GridFS spec by many years. The Go driver has to be ready to parse the length as an int32.

https://jira.mongodb.org/browse/PYTHON-1738?focusedCommentId=2139094&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-2139094

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