Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Validator][RecursiveContextualValidator] Prevent validated hash collisions#36415

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@fancyweb
Copy link
Contributor

QA
Branch?3.4
Bug fix?yes
New feature?-
Deprecations?-
Tickets-
LicenseMIT
Doc PR-

RecursiveContextualValidator usesspl_object_hash at different places to generate cache keys. The problem with this method is that there can be collisions (same hash for two different objects) since once an object is destroyed,spl_object_hash can return a previously used hash.

I encountered the problem on a project with constraints that are created on the fly. The first constraint is applied and is "cached". Then it is destroyed. Then another constraint happen to have the exact samespl_object_hash. It is skipped while it would cause violations. I was able to reproduce the problem consistently in the unit test.

The easy way to deal with this is to keep references to all objects (proposed solution). But I guess it could leak too much.

We could also try to "clean" theExecutionContext stores at the end of the three validate methods. However, we would still need to keep references to the initialized objects since they must really be initialized one time, even on multiple calls

if (\is_object($group)) {
$groupHash =spl_object_hash($group);

if (!isset($this->validatedObjectsReferences[$groupHash])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed for group sequences?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

GroupSequences can suffer from the same problem since they can be passed directly to the validate method as objects.

@nicolas-grekasnicolas-grekas modified the milestones:4.4,3.4Apr 10, 2020
@nicolas-grekas
Copy link
Member

We should find a place where these arrays can be emptied. The memory leak should be avoided.

@fancyweb
Copy link
ContributorAuthor

We should find a place where these arrays can be emptied. The memory leak should be avoided.

I think we can clear constraints and group sequences arrays at the end of each validate methods. However, we can never clean the initialized objects. Would that work for you?

@fancywebfancywebforce-pushed thevalidator-spl-object-hash branch fromf8cea76 to146634dCompareApril 17, 2020 13:35
@fabpot
Copy link
Member

@fancyweb What's the status of this PR?

@fancyweb
Copy link
ContributorAuthor

I need to check Nicolas's suggestion, please keep it open.

@fancywebfancywebforce-pushed thevalidator-spl-object-hash branch from146634d to6f28e2dCompareAugust 14, 2020 08:22
@fancywebfancywebforce-pushed thevalidator-spl-object-hash branch from6f28e2d to1ec0d3aCompareAugust 14, 2020 08:23
@fancyweb
Copy link
ContributorAuthor

We should find a place where these arrays can be emptied. The memory leak should be avoided.

I think we can clear constraints and group sequences arrays at the end of each validate methods. However, we can never clean the initialized objects. Would that work for you?

Unfortunately that does not work. I had to remove this part.

@xabbuh
Copy link
Member

Can you update theFormValidator class to remove the$fieldFormConstraint = new Form() statements (can be replaced with$formConstraint). These statements were only added in#36865 to precisely prevent the collisions being fixed here.

@fancyweb
Copy link
ContributorAuthor

@xabbuh I looked at this a few days ago but it needs more work. My patch does not fix all cases because it does not take into account the current defaultPropertyPath. One of FormValidator tests fails because of this. You can have a look if you want to.

@xabbuh
Copy link
Member

continued in#38387, thanks for starting the work on this@fancyweb

@xabbuhxabbuh closed thisOct 2, 2020
@fancywebfancyweb deleted the validator-spl-object-hash branchOctober 2, 2020 13:37
xabbuh added a commit that referenced this pull requestNov 13, 2020
…t hashes (fancyweb, xabbuh)This PR was merged into the 4.4 branch.Discussion----------[Validator] prevent hash collisions caused by reused object hashes| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       |Fix#36415| License       | MIT| Doc PR        |Commits-------8dd1a6e prevent hash collisions caused by reused object hashes9645fa3 [Validator][RecursiveContextualValidator] Prevent validated hash collisions
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

+1 more reviewer

@HeahDudeHeahDudeHeahDude left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

6 participants

@fancyweb@nicolas-grekas@fabpot@xabbuh@HeahDude@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp