-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 5.7.0
-
Component/s: BSON
What problem are you facing?
The Binary's toString method returns more bytes than will be used in the processing of serializing it to BSON. The position property of the Binary class is used to determine how much of the byte sequence is serialized and it should be respected by other conversion methods for consistency in interpreting the contents of the Binary.
Steps to reproduce?
const bin = new BSON.Binary(); // Binary.createFromBase64("", 0) bin.toString() // '\x00\x00\x00\x00...' (256 zeros) BSON.serialize({ bin }) // 0F000000 05 62696E00 00000000 00 00 // Above is a bson document with key "bin\x00", followed by an int32 size = 0, subtype = 0
User Impact
- After round-tripping a Binary through BSON the return value from toString can be different.
Dependencies
- Driver
Unknowns
- Are there other cases where the position isn't correctly being used where it should?
Acceptance Criteria
Implementation Requirements
- Create a subarray on the buffer before turning it into a string
- Create a subarray on the buffer before turning it into JSON (adjacent functionality)
Testing Requirements
- Round trip a binary through BSON serialize and assert the toString result is the same even if the original buffers are not.
- ^^ same test, but with toJSON
Documentation Requirements
- TBD
Follow Up Requirements
- TBD
- related to
-
NODE-4855 Add static fromX bson type creation methods to Binary and ObjectId
- Closed
1.
|
6.x Fix | NODE-6042 | Closed | Aditi Khare | bson-6.6.0 | |
2.
|
5.x fix | NODE-6043 | Closed | Aditi Khare | bson-5.5.2 |