[GODRIVER-2311] Byte array reuse in BSON unmarshalling may cause duplicated values Created: 14/Feb/22 Updated: 28/Oct/23 Resolved: 16/Mar/22 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | 1.0.4 |
| Fix Version/s: | 1.9.0, 1.8.5, 1.7.6 |
| Type: | Bug | Priority: | Blocker - P1 |
| Reporter: | Matt Dale | Assignee: | Matt Dale |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Cloud Backport: | Needed |
| Description |
|
Updated:
Check out a repro example here (note that the example doesn't repro the problem on the Go Playground as of the 1.8.5/1.9.0 releases, which fix the bug): https://go.dev/play/p/-BjGJ9OjAVB Note that this only applies to unmarshaling into byte slice values, not byte array values. For example, values unmarshaled to a struct containing a [16]byte field are not affected. However, the same BSON document unmarshaled to a bson.D will infer the value type is a []byte and will be affected. Original: The duplication bug is fixed by this commit which makes a copy of the input file byte buffer. That fix suggesting the root cause of the issue may be some input byte array reuse in the returned value (i.e. the BSON Unmarshal function returns an unmarshalled value with byte slices that point to sections of the same byte array as the input data). That can lead to unexpected value duplication or corruption if the input byte array is modified after unmarshalling a value (modifying the input byte slice/array after Unmarshal returns is a valid use case). Try to detect the possible issue using the following process:
E.g. getting underlying array addresses of a slice:
|
| Comments |
| Comment by Githook User [ 04/Apr/22 ] |
|
Author: {'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}Message: Co-authored-by: Matt Dale <9760375+matthewdale@users.noreply.github.com> |
| Comment by Githook User [ 31/Mar/22 ] |
|
Author: {'name': 'Matt Dale', 'email': '9760375+matthewdale@users.noreply.github.com', 'username': 'matthewdale'}Message: |
| Comment by Githook User [ 31/Mar/22 ] |
|
Author: {'name': 'Matt Dale', 'email': '9760375+matthewdale@users.noreply.github.com', 'username': 'matthewdale'}Message: |
| Comment by Githook User [ 22/Mar/22 ] |
|
Author: {'name': 'Matt Dale', 'email': '9760375+matthewdale@users.noreply.github.com', 'username': 'matthewdale'}Message: |
| Comment by Githook User [ 16/Mar/22 ] |
|
Author: {'name': 'Matt Dale', 'email': '9760375+matthewdale@users.noreply.github.com', 'username': 'matthewdale'}Message: |
| Comment by Matt Dale [ 14/Mar/22 ] |