[SERVER-43071] toBsonSafeWithDiscriminator mistakenly inverts discriminator byte Created: 28/Aug/19  Updated: 29/Oct/23  Resolved: 30/Aug/19

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: None
Fix Version/s: 4.3.1

Type: Bug Priority: Major - P3
Reporter: Xiangyu Yao (Inactive) Assignee: Xiangyu Yao (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Execution Team 2019-09-09
Participants:
Linked BF Score: 0

 Description   

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.



 Comments   
Comment by Githook User [ 29/Aug/19 ]

Author:

{'email': 'xiangyu.yao@mongodb.com', 'name': 'Xiangyu Yao', 'username': 'xy24'}

Message: SERVER-43071 Fix the bug in KeyString::toBsonSafeWithDiscriminator which mistakenly invert discriminator byte
Branch: master
https://github.com/mongodb/mongo/commit/8ce7a9da5e5c35aab9324a8b2b1b64ad8ca4d608

Generated at Thu Feb 08 05:02:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.