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

Go driver cannot decode gridfs files collection documents if the chunksize field is not stored as int32

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 1.7.4
    • Affects Version/s: None
    • Component/s: GridFS
    • Fully Compatible

      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.

      But the Go driver does not handle existing GridFS files if the chunksize type is not int32. It will panic with the following error:

      panic: Call of bsoncore.Value.Int32 on 64-bit integer type
      
      goroutine 1274825 [running]:
      go.mongodb.org/mongo-driver/x/bsonx/bsoncore.Value.Int32(0xc007ee2012, 0xc007ee2066, 0x8, 0x12715, 0x1)
              /go/pkg/mod/go.mongodb.org/mongo-driver@v1.7.3/x/bsonx/bsoncore/value.go:755 +0x187
      go.mongodb.org/mongo-driver/bson.RawValue.Int32(...)
              /go/pkg/mod/go.mongodb.org/mongo-driver@v1.7.3/bson/raw_value.go:263
      go.mongodb.org/mongo-driver/mongo/gridfs.(*DownloadStream).fillBuffer(0xc002042af0, 0x109b740, 0xc000118000, 0x109b740, 0xc000118000)
              /go/pkg/mod/go.mongodb.org/mongo-driver@v1.7.3/mongo/gridfs/download_stream.go:245 +0x260
      go.mongodb.org/mongo-driver/mongo/gridfs.(*DownloadStream).Read(0xc002042af0, 0xc004a48600, 0x200, 0x200, 0x0, 0x0, 0x0)
              /go/pkg/mod/go.mongodb.org/mongo-driver@v1.7.3/mongo/gridfs/download_stream.go:158 +0x1cc
      bytes.(*Buffer).ReadFrom(0xc0011a7bf0, 0x10918a0, 0xc002042af0, 0x7fea00439180, 0xc0011a7bf0, 0xa80f01)
              /usr/local/go/src/bytes/buffer.go:204 +0xb1
      io.copyBuffer(0x1091140, 0xc0011a7bf0, 0x10918a0, 0xc002042af0, 0x0, 0x0, 0x0, 0xfc11f470bcae5907, 0x72458b000c, 0x0)
              /usr/local/go/src/io/io.go:391 +0x2fc
      io.Copy(...)
              /usr/local/go/src/io/io.go:364
      go.mongodb.org/mongo-driver/mongo/gridfs.(*Bucket).downloadToStream(0xc00cf900b0, 0xc002042af0, 0x1091140, 0xc0011a7bf0, 0x0, 0x0, 0x2c)
              /go/pkg/mod/go.mongodb.org/mongo-driver@v1.7.3/mongo/gridfs/bucket.go:419 +0xa8
      go.mongodb.org/mongo-driver/mongo/gridfs.(*Bucket).DownloadToStream(0xc00cf900b0, 0xa22c40, 0xc0066cdf00, 0x1091140, 0xc0011a7bf0, 0x0, 0x0, 0xa7f597)
              /go/pkg/mod/go.mongodb.org/mongo-driver@v1.7.3/mongo/gridfs/bucket.go:209 +0x9e
      
      

            Assignee:
            gabriela.asuncion@mongodb.com Gabby Asuncion
            Reporter:
            jeancarlo.ortiz@wiztopic.com Jean Carlo Ortiz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: