Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-809

Go driver cannot decode gridfs files collection documents if the length field is not stored as int64

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.0.1
    • Affects Version/s: None
    • Component/s: GridFS
    • Labels:
      None

      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
      

       

            Assignee:
            go-community-user Go Community User
            Reporter:
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: