[CDRIVER-3913] Reduce likelihood of colliding ObjectID random sequence Created: 24/Feb/21 Updated: 23/May/22 Resolved: 23/May/22 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Kevin Albertson | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Case: | (copied to CRM) | ||||||||||||||||
| Description |
|
ObjectID random values and the counter sequence is seeded from combining time, PID, and hostname as noted in the ObjectID specification. The seed is generated in _bson_context_init_random as an XOR of:
jmikola identified two possible problems with the current seed generation: PID uint16_t truncation Looking at the implementation of _bson_getpid:
The truncation of a signed wider integer type to a narrower unsigned type is likely undefined, and could run the risk of two different process IDs colliding. The value of _bson_getpid is only used as part of the random seed in _bson_context_init_random, which is already generated from an int. Let's store this directly as a 32 bit integer type as input to the random seed if possible. Duplicate seeds from sequential XORs
A plausible solution may be to bit shift before XORing. Testing |