Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] Prevent a loop in aliases within the findDefinition method #25364

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

Merged

Conversation

sroze
Copy link
Contributor

@sroze sroze commented Dec 6, 2017

Q A
Branch? 3.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #25338
License MIT
Doc PR ø

This prevents an infinite loop going when aliases reference themselves. This is based on 3.3 as the "normalized ID" changed to allow non-lowercase names. Fixing this in 2.7 would mean a merge conflict that IMO is not worth it.

@sroze sroze force-pushed the bugfix-25338-prevent-definition-alias-loop branch from c716668 to 22f3523 Compare December 6, 2017 16:40
@sroze
Copy link
Contributor Author

sroze commented Dec 6, 2017

AppVeyor's failure is not related... memory on composer ... 💥

while (isset($this->aliasDefinitions[$id])) {
$id = (string) $this->aliasDefinitions[$id];

if (isset($seen[$id])) {
throw new ServiceCircularReferenceException($id, array_keys($seen));
Copy link
Member

Choose a reason for hiding this comment

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

The message should be improved see the CheckCircularReferencePass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean?

Copy link
Member

@nicolas-grekas nicolas-grekas Dec 7, 2017

Choose a reason for hiding this comment

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

Sorry was on mobile :)
This is what I mean:

if (isset($seen[$id])) {
    $seen = array_slice($seen, array_search($id, $seen));
    $seen[] = $id;

    throw new ServiceCircularReferenceException($id, $seen);
}

$seen[$id] = $id;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see the idea. Tho, we can't use array_slice with string keys in an array, we'll have to use 2 of them.

@nicolas-grekas
Copy link
Member

Thanks for the PR.

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

LGTM

@ro0NL
Copy link
Contributor

ro0NL commented Dec 6, 2017

The same loop can happen in get() right?

@nicolas-grekas
Copy link
Member

The same loop can happen in get() right?

Yes, but is already handled there AFAIK.

@leotiger
Copy link

leotiger commented Dec 7, 2017

I've tested the fix and it throws now a circular reference exception as expected. Thx.

@fabpot
Copy link
Member

fabpot commented Dec 7, 2017

Thank you @sroze.

@fabpot fabpot merged commit 22f3523 into symfony:3.3 Dec 7, 2017
fabpot added a commit that referenced this pull request Dec 7, 2017
… `findDefinition` method (sroze)

This PR was merged into the 3.3 branch.

Discussion
----------

[DependencyInjection] Prevent a loop in aliases within the `findDefinition` method

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25338
| License       | MIT
| Doc PR        | ø

This prevents an infinite loop going when aliases reference themselves. This is based on 3.3 as the "normalized ID" changed to allow non-lowercase names. Fixing this in 2.7 would mean a merge conflict that IMO is not worth it.

Commits
-------

22f3523 Prevent a loop in aliases within the `findDefinition` method
@sroze sroze deleted the bugfix-25338-prevent-definition-alias-loop branch December 8, 2017 09:36
nicolas-grekas added a commit that referenced this pull request Dec 8, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

[DI] Fix circular-aliases message

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      |
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

The missing bits in #25364

Commits
-------

f1a7b07 [DI] Fix circular-aliases message
This was referenced Dec 15, 2017
@fabpot fabpot mentioned this pull request Jan 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants