[GODRIVER-2204] Go driver cannot decode gridfs files collection documents if the chunksize field is not stored as int32 Created: 22/Oct/21  Updated: 28/Oct/23  Resolved: 02/Nov/21

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

Type: Bug Priority: Unknown
Reporter: Jean Carlo Ortiz Assignee: Gabby Asuncion
Resolution: Fixed Votes: 0
Labels: GridFS
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 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.

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



 Comments   
Comment by Githook User [ 03/Nov/21 ]

Author:

{'name': 'Gabriela Asuncion', 'email': 'gabriela.asuncion@mongodb.com', 'username': 'gabbyasuncion'}

Message: GODRIVER-2204: Add chunkIndex workaround to fillBuffer (#783)
Branch: release/1.7
https://github.com/mongodb/mongo-go-driver/commit/5089f6f4f0b3fe8cc103395e38746b7600044c7d

Comment by Githook User [ 02/Nov/21 ]

Author:

{'name': 'Gabriela Asuncion', 'email': 'gabriela.asuncion@mongodb.com', 'username': 'gabbyasuncion'}

Message: GODRIVER-2204: Add chunkIndex workaround to fillBuffer (#783)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/6597bd7b8ea5f88b2918b3d7423a5e5cc69cb091

Comment by Gabby Asuncion [ 01/Nov/21 ]

Hi jeancarlo.ortiz@wiztopic.com, do you mind sharing which use case produced this panic?

Comment by Kevin Albertson [ 25/Oct/21 ]

Hi jeancarlo.ortiz@wiztopic.com, thank you for filing this bug report. We will take a look soon.

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