Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1930

Pure python BSON decoders don't support memoryviews with offsets

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.9
    • BSON
    • None

    Description

      PYTHON-1785 implemented support for BSON decoding from memoryview objects but it does not support memoryviews with offsets, eg:

      >>> from bson import decode, encode
      >>> decode(memoryview(encode({})))
      {}
      >>> decode(memoryview(b'123'+encode({}))[3:])
      Traceback (most recent call last):
        File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 484, in _bson_to_dict
          _, end = _get_object_size(data, 0, len(data))
        File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 232, in _get_object_size
          if data[end] != _OBJEND:
      IndexError: index out of range
       
      During handling of the above exception, another exception occurred:
       
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 983, in decode
          return _bson_to_dict(data, codec_options)
        File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 491, in _bson_to_dict
          reraise(InvalidBSON, exc_value, exc_tb)
        File "/Users/shane/git/mongo-python-driver/bson/py3compat.py", line 53, in reraise
          raise exctype(str(value)).with_traceback(trace)
        File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 484, in _bson_to_dict
          _, end = _get_object_size(data, 0, len(data))
        File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 232, in _get_object_size
          if data[end] != _OBJEND:
      bson.errors.InvalidBSON: index out of range
      

      Attachments

        Issue Links

          Activity

            People

              shane.harvey@mongodb.com Shane Harvey
              shane.harvey@mongodb.com Shane Harvey
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: