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

Pure python BSON decoders don't support memoryviews with offsets

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.9
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:
      None

      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
      

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

              Created:
              Updated:
              Resolved: