Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-41994

Shell does not add length to BSON binary subtype 2

    • Type: Icon: Bug Bug
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Shell
    • Server Development Platform
    • Fully Compatible
    • ALL
    • Hide

      In the shell insert a BinData with subtype 2:

      > db.coll.insert({x: BinData(2, '1234')})
      

      And in the driver you try to read that, you get a parsing exception:

      > python -i
      >>> from pymongo import MongoClient
      >>> c = MongoClient()
      >>> c.test.test.find_one()
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/collection.py", line 1267, in find_one
          for result in cursor.limit(-1):
        File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/cursor.py", line 1200, in next
          if len(self.__data) or self._refresh():
        File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/cursor.py", line 1114, in _refresh
          self.__send_message(q)
        File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/cursor.py", line 988, in __send_message
          codec_options=self.__codec_options)
        File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/cursor.py", line 1077, in _unpack_response
          return response.unpack_response(cursor_id, codec_options)
        File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/message.py", line 1474, in unpack_response
          return bson.decode_all(self.payload_document, codec_options)
      bson.errors.InvalidBSON: invalid length or type code
      
      Show
      In the shell insert a BinData with subtype 2: > db.coll.insert({x: BinData(2, '1234')}) And in the driver you try to read that, you get a parsing exception: > python -i >>> from pymongo import MongoClient >>> c = MongoClient() >>> c.test.test.find_one() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/collection.py", line 1267, in find_one for result in cursor.limit(-1): File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/cursor.py", line 1200, in next if len(self.__data) or self._refresh(): File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/cursor.py", line 1114, in _refresh self.__send_message(q) File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/cursor.py", line 988, in __send_message codec_options=self.__codec_options) File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/cursor.py", line 1077, in _unpack_response return response.unpack_response(cursor_id, codec_options) File "/Users/kevinalbertson/code/mongo-python-driver/pymongo/message.py", line 1474, in unpack_response return bson.decode_all(self.payload_document, codec_options) bson.errors.InvalidBSON: invalid length or type code
    • Dev Tools 2019-09-09, Dev Tools 2019-09-09, Dev Tools 2019-09-23, Dev Tools 2020-01-13, Dev Tools 2020-01-27, Dev Tools 2020-02-24
    • 50

      Per SPEC-1338, the shell does not serialize BSON binary subtype 2 the same way drivers do, which drivers do not recognize as valid. bsonspec.org states:

      \x02 Binary (Old) - This used to be the default subtype, but was deprecated in favor of \x00. Drivers and tools should be sure to handle \x02 appropriately. The structure of the binary data (the byte* array in the binary non-terminal) must be an int32 followed by a (byte*). The int32 is the number of bytes in the repetition.

      But the shell does not appear to add the four byte integer length.

            Assignee:
            backlog-server-devplatform [DO NOT ASSIGN] Backlog - Server Development Platform Team (SDP) (Inactive)
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: