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

BSON C extensions cannot encode Timestamps with high order bit set on seconds or increment

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

      The updated bson corpus Timestamp tests are failing on Windows:

       [2017/08/03 16:33:05.915] ERROR [0.003s]: test_timestamp (test_bson_corpus.TestBSONCorpus)
       [2017/08/03 16:33:05.915] ----------------------------------------------------------------------
       [2017/08/03 16:33:05.915] Traceback (most recent call last):
       [2017/08/03 16:33:05.915]   File "C:\data\mci\454d5a8071c07aeb00e529e6e45a378b\src\test\test_bson_corpus.py", line 174, in run_test
       [2017/08/03 16:33:05.915]     self.assertEqual(encode_bson(decoded_bson), cB)
       [2017/08/03 16:33:05.915]   File "C:\data\mci\454d5a8071c07aeb00e529e6e45a378b\src\bson\__init__.py", line 976, in encode
       [2017/08/03 16:33:05.915]     return cls(_dict_to_bson(document, check_keys, codec_options))
       [2017/08/03 16:33:05.915] OverflowError: Python int too large to convert to C long
      

      The problem is the C extensions convert the Timestamp.inc and Timestamp.time fields to a C long which is only guaranteed to be at least 32-bits. If long is 32 bits then a time or increment greater than 2147483647 will overflow. For example,

      >>> BSON.encode({'t':Timestamp(0x80000000, 1)})
      *** OverflowError: Python int too large to convert to C long
      >>> BSON.encode({'t':Timestamp(0x80000000-1, 1)})
      b'\x10\x00\x00\x00\x11t\x00\x01\x00\x00\x00\xff\xff\xff\x7f\x00'
      

      We should use an unsigned long or a long long instead.

            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: