Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-5497

BSON Binary toString method returns more data than is serialized to BSON

    • 2
    • 0
    • Not Needed
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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

        There are no Sub-Tasks for this issue.

            Assignee:
            aditi.khare@mongodb.com Aditi Khare
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Warren James
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: