Repository navigation
Conversation
New contact method values get a key with a 3 character random hash (4096 possibilities) and nothing checked whether the key was in use, so adding a value could silently overwrite an existing one. Generate a new hash until the key is free. This also caused the intermittent test_overwrite_existing_fields_update failure.
ReviewHigh: none. Medium: none. The
The PR looks ready to merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a contact method value (email, phone, …) is added,
Disciple_Tools_Posts::add_post_contact_method()stores it undercontact_<type>_<hash>, where the hash is 3 characters fromsubstr( md5( rand( 10000, 100000 ) ), 0, 3 )— about 4096 possible keys. Nothing checked whether the key already existed, so when it did,update_post_meta()silently replaced the existing value.Each added value collides with probability ≈ (existing values of that type) / 4096. On a local site, adding 200 emails one at a time to a contact kept only 196 and 197 of 200 in two runs.
This is also the cause of the intermittent CI failure in
DT_Posts_DT_Posts_Update_Post::test_overwrite_existing_fields_update(Undefined array key 1atunit-test-update-post.php:276): the new email occasionally replaced the fixture's existing one.Change
Generate a new hash until
metadata_exists()reports the key is free. The key format is unchanged.Testing
php -lpass.🤖 Generated with Claude Code