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

toBsonSafeWithDiscriminator mistakenly inverts discriminator byte

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.3.1
    • Affects Version/s: None
    • Component/s: Storage
    • None
    • Fully Compatible
    • ALL
    • Execution Team 2019-09-09
    • 0

      toBsonSafeWithDiscriminator is a helper function which deserializes a KeyString with discriminator byte back to BSON with discriminator field name.

      The KeyString passed in could have fewer fields than the BSON index key, for example:
      We could have a index key like: {:3, :5, :7}
      Now we want to query {:3, "g": 5, :7} ("g" means strictly greater than 5 here). The KeyString finally generated would be {:3, "g": 5} in the KeyString form.

      Now if you try to deserialize it back to the BSON, it will still think it has the third field and tries to invert whatever byte (in this case, discriminator byte) if the Ordering on the third field is -1. And this mistakenly inverts the discriminator byte.

      To fix this function, we could choose not to invert the discriminator byte. There is no easy way to detect how many fields the KeyString has and since this is a helper function only used by EphemeralForTest, it should be fine.

            Assignee:
            xiangyu.yao@mongodb.com Xiangyu Yao (Inactive)
            Reporter:
            xiangyu.yao@mongodb.com Xiangyu Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: