[GODRIVER-802] Document fields corrupted in transformAndEnsureID Created: 01/Feb/19  Updated: 28/Oct/23  Resolved: 08/Feb/19

Status: Closed
Project: Go Driver
Component/s: CRUD
Affects Version/s: None
Fix Version/s: 1.0.0-rc1

Type: Bug Priority: Major - P3
Reporter: Pavel Antonov Assignee: Isabella Siu (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

If document contains binary fields at the beginning of structure, data in fields will be overwritten with "_id" and corrupted.

Code:

client, _ := mongo.NewClient("mongodb://localhost:27017")
client.Connect(context.TODO())
db := client.Database("test")
 
type D struct {
   Bin []byte `bson:"bin"`
   ID  string `bson:"_id"`
}
d := &D{
   Bin: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
   ID:  "LongEnoughIdentifier",
}
 
_, err := db.Collection("test").InsertOne(context.TODO(), d)

As result "bin" field will contains []byte("Identifier") instead of zeros.

Cause of error, using same buffer (var buf) for document data values and _id  encoding/decoding. Here: https://github.com/mongodb/mongo-go-driver/blob/42e68e39d0196d841aed31ec9e40e80edb4f1566/mongo/mongo.go#L120

 



 Comments   
Comment by Githook User [ 08/Feb/19 ]

Author:

{'name': 'Isabella Siu', 'email': 'isabella.siu@10gen.com', 'username': 'iwysiu'}

Message: GODRIVER-802 fix document fields corrupted in transformAndEnsureID

Change-Id: I20957caedda200b1ffd8db3738d562798abbf6f9
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/55ec0894785b750e5fb0ab6aac13218b59e4627f

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