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

Shell does not add length to BSON binary subtype 2

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 4.3 Required
    • Component/s: Shell
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      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
    • Sprint:
      Dev Tools 2019-09-09, Dev Tools 2019-09-09, Dev Tools 2019-09-23, Dev Tools 2020-01-13 real
    • Linked BF Score:
      50

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                11 Start watching this issue

                Dates

                • Created:
                  Updated: