Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: Fix bug in deepCompare which would incorrectly return objects with disjoint keys as equal #2586

Merged
merged 3 commits into from
Sep 1, 2022

Conversation

3nprob
Copy link
Contributor

@3nprob 3nprob commented Aug 11, 2022

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

Type: Defect


Here's what your changelog entry will look like:

🐛 Bug Fixes

  • utils: Fix bug in deepCompare which would incorrectly return objects with disjoint keys as equal (#2586). Contributed by @3nprob.

@github-actions github-actions bot added the Z-Community-PR Issue is solved by a community member's PR label Aug 11, 2022
@3nprob
Copy link
Contributor Author

3nprob commented Aug 11, 2022

Signed-off-by: 3nprob <[email protected]>

@3nprob 3nprob marked this pull request as ready for review August 11, 2022 11:01
@3nprob 3nprob requested a review from a team as a code owner August 11, 2022 11:01
@3nprob
Copy link
Contributor Author

3nprob commented Aug 11, 2022

This function is used in these places in this repo. While it's involved in cryptographic key management I don't immediately see how this can become an actual security issue.

if (utils.deepCompare(existing.requestBody, requestBody)) {

if (utils.deepCompare(existing.requestBody, requestBody)) {

if (utils.deepCompare(oldDef, newDef)) {

@3nprob
Copy link
Contributor Author

3nprob commented Aug 11, 2022

@turt2live @richvdh (Since I see you as the users of this function when looking at the blame)

@turt2live
Copy link
Member

hey @3nprob - thanks for the PR. Would it be possible to get a de-anonymized signoff on your PRs, or a form filled out with [email protected] (email) please? Thanks

@3nprob
Copy link
Contributor Author

3nprob commented Aug 11, 2022

hey @3nprob - thanks for the PR. Would it be possible to get a de-anonymized signoff on your PRs, or a form filled out with [email protected] (email) please? Thanks

I'd rather stay pseudonymous for the time being. Invited you for DM on Matrix just now. I could take a look at the form - e-mail in the signoff should work.

@turt2live
Copy link
Member

If you've invited me to a DM, I did not get it 😅 - I'm @travis:t2l.io on Matrix

@3nprob
Copy link
Contributor Author

3nprob commented Aug 11, 2022

So we did have a brief chat just now.

Unfortunately I had missed this before starting work: https://github.com/matrix-org/matrix-js-sdk/blob/develop/CONTRIBUTING.md#sign-off

We accept contributions under a legally identifiable name, such as your name on government documentation or common-law names (names claimed by legitimate usage or repute). Unfortunately, we cannot accept anonymous contributions at this time.

I submit and make my patches available under the Apache License and have agreed to the DCO, which I have signed off on. Element is free to use these patches under the license, all I ask is that the license terms including attribution are followed.

However, requiring contributors to doxx themselves (in a way legally recognized in the UK, I assume here) is not something I find comfortable with for a project such as this (which is kind of OT here; just explaining my rationale for any onlookers wondering why this is hanging).

Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I see the actual code change which matches the title here - it looks like a general refactoring rather than a bug fix?

@3nprob
Copy link
Contributor Author

3nprob commented Aug 24, 2022

not sure I see the actual code change which matches the title here - it looks like a general refactoring rather than a bug fix?

The existing code is asymmetric and checks one direction twice and never the other. Check out and run just the added regression cases and you should see them fail.

@3nprob
Copy link
Contributor Author

3nprob commented Aug 28, 2022

For anyone wondering what the status is re the sign-off conversation above: Got put in touch with someone else from the Matrix Foundation and they came up with something that was acceptable so this PR should be good to go and they told me that this is now unblocked in that regard as of Wednesday last week.

Also just rebased on current develop.

@3nprob
Copy link
Contributor Author

3nprob commented Aug 30, 2022

Rebased on develop

This test wrongly asserted that `initialSyncLimit` would be used to make a filter
It is used only for the initial sync inline filter, and not in POST /filter
@t3chguy
Copy link
Member

t3chguy commented Sep 1, 2022

@3nprob my PR was related to the test failure, but not due to the code being buggy, but the test making the wrong assertions

Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Apologies it took so long for this one to go through: it managed to hit just about every internal process unexpectedly :)

if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
return false;
}
}

// finally, compare each of x's keys with y
for (p in y) { // eslint-disable-line guard-for-in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, it was pointed out to me that this is the bug I couldn't see: y is meant to be x.

@turt2live turt2live enabled auto-merge (squash) September 1, 2022 21:35
@turt2live turt2live merged commit e87ce87 into matrix-org:develop Sep 1, 2022
@3nprob
Copy link
Contributor Author

3nprob commented Sep 2, 2022

@3nprob my PR was related to the test failure, but not due to the code being buggy, but the test making the wrong assertions

Or more precisely: The bug existed before and after your PR but some assertions were missing in the tests,making it go undetected. This PR added those assertions.

@3nprob
Copy link
Contributor Author

3nprob commented Sep 2, 2022

Just curious; Why did e808e0f become part of this PR and not opened as its own? Looks like a completely separate issue and only tangentially related through the tests.

The resulting commit e87ce87 makes it look like a single change.

EDIT: Realized I prematurely deleted the branch on GH before fetching it... web archive mirror is not pretty but should work to distinguish in case the GH links stop.

@3nprob 3nprob deleted the fix-deepcompare branch September 2, 2022 01:24
@t3chguy
Copy link
Member

t3chguy commented Sep 2, 2022

@3nprob it became part of this PR to get your tests passing, we squash merge by policy hence it becoming a single commit

su-ex added a commit to SchildiChat/matrix-js-sdk that referenced this pull request Sep 15, 2022
* Fix bug in deepCompare which would incorrectly return objects with disjoint keys as equal ([\matrix-org#2586](matrix-org#2586)). Contributed by @3nprob.
* Refactor Sync and fix `initialSyncLimit` ([\matrix-org#2587](matrix-org#2587)).
* Use deep equality comparisons when searching for outgoing key requests by target ([\matrix-org#2623](matrix-org#2623)). Contributed by @duxovni.
* Fix room membership race with PREPARED event ([\matrix-org#2613](matrix-org#2613)). Contributed by @jotto.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Defect Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants