eclipse-cyclonedds / cyclonedds-cxx

Other
93 stars 74 forks source link

Cyclone C++ binding mishandles keys with MD5 collisions #496

Open eboasson opened 3 months ago

eboasson commented 3 months ago

Two samples with a different key value must result in different instances. The Cyclone C++ binding mishandles the case where the MD5 of the key values are the same. The example in md5.zip demonstrates the problem:

C (correct)

subscriber sees two different instances (ph is publication handle, ih is instance handle) and sees them both get disposed:

# bin/Debug/md5c sub & bin/Debug/md5c pub A 0 write & (sleep 1 ; bin/Debug/md5c pub B 1 write) & sleep 15 ; kill %1
[1] 34924
[2] 34925
[3] 34926
Waiting for data ...
1719827914868438000ns pub A seq 0 inst 8771f2b4a82b...: write
1719827914872036000 RHC now:
  is/vs/ss A/N/F ph 4078469049691875558 ih 13760939914493807832 key 8771f2b4a82b... pubid A seq 0
1719827915630491000ns pub B seq 0 inst 07f1723428ab...: write
1719827915631249000 RHC now:
  is/vs/ss A/O/S ph 4078469049691875558 ih 13760939914493807832 key 8771f2b4a82b... pubid A seq 0
  is/vs/ss A/N/F ph 5875877159332482042 ih 2957197498886303048 key 07f1723428ab... pubid B seq 0
1719827921879002000 pub done
1719827921882471000 RHC now:
  is/vs/ss D/O/S ph 4078469049691875558 ih 13760939914493807832 key 8771f2b4a82b... pubid A seq 0
  is/vs/ss D/O/F ph 4078469049691875558 ih 13760939914493807832 key 8771f2b4a82b...
  is/vs/ss A/O/S ph 5875877159332482042 ih 2957197498886303048 key 07f1723428ab... pubid B seq 0
[2]  - 34925 done       bin/Debug/md5c pub A 0 write
1719827922636974000 pub done
1719827922638102000 RHC now:
  is/vs/ss D/O/S ph 4078469049691875558 ih 13760939914493807832 key 8771f2b4a82b... pubid A seq 0
  is/vs/ss D/O/S ph 4078469049691875558 ih 13760939914493807832 key 8771f2b4a82b...
  is/vs/ss D/O/S ph 5875877159332482042 ih 2957197498886303048 key 07f1723428ab... pubid B seq 0
  is/vs/ss D/O/F ph 5875877159332482042 ih 2957197498886303048 key 07f1723428ab...
[3]  + 34926 done       ( sleep 1; bin/Debug/md5c pub B 1 write; )
[1]  + 34924 terminated  bin/Debug/md5c sub

C++ (incorrect)

Subscriber sees one only instance with two writers:

# bin/Debug/md5cxx sub & bin/Debug/md5cxx pub A 0 write & (sleep 1 ; bin/Debug/md5cxx pub B 1 write) & sleep 15 ; kill %1
[1] 34944
[2] 34945
[3] 34946
Waiting for data ...
4075033754101750ns pub A seq 0 inst 8771f2b4a82b...: write
4075033759483583ns RHC now:
  is/vs/ss A/N/F ph 10077226761809638063 ih 12706308632790722314 key 8771f2b4a82b... pubid A seq 0
4075034528896916ns pub B seq 0 inst 07f1723428ab...: write
4075034531500541ns RHC now:
  is/vs/ss A/O/F ph 10741780872057002482 ih 12706308632790722314 key 07f1723428ab... pubid B seq 0
4075040761509041ns pub done
[2]  - 34945 done       bin/Debug/md5cxx pub A 0 write
4075041535606000ns pub done
4075041537725000ns RHC now:
  is/vs/ss D/O/S ph 10741780872057002482 ih 12706308632790722314 key 07f1723428ab... pubid B seq 0
  is/vs/ss D/O/F ph 10741780872057002482 ih 12706308632790722314 key 8771f2b4a82b...
[3]  + 34946 done       ( sleep 1; bin/Debug/md5cxx pub B 1 write; )
[1]  + 34944 terminated  bin/Debug/md5cxx sub